nextras-orm-generator icon indicating copy to clipboard operation
nextras-orm-generator copied to clipboard

$primary must not be accessed before initialization

Open MKI-Miro opened this issue 1 year ago • 1 comments

Ahojte

Po update na 6.0.1 tu mame novu chybu:

Fatal error: Uncaught Error: Typed property Contributte\Nextras\Orm\Generator\Entity\PhpRelDoc::$primary must not be accessed before initialization in \vendor\contributte\nextras-orm-generator\src\Entity\PhpRelDoc.php:132 Stack trace: #0 \vendor\contributte\nextras-orm-generator\src\Entity\PhpDoc.php(150): Contributte\Nextras\Orm\Generator\Entity\PhpRelDoc->__toString() #1 \vendor\contributte\nextras-orm-generator\src\Generator\Entity\Decorator\ColumnDocumentor.php(73): Contributte\Nextras\Orm\Generator\Entity\PhpDoc->__toString() #2 \vendor\contributte\nextras-orm-generator\src\Generator\Entity\EntityGenerator.php(60): Contributte\Nextras\Orm\Generator\Generator\Entity\Decorator\ColumnDocumentor->doDecorate(Object(Contributte\Nextras\Orm\Generator\Entity\Column), Object(Nette\PhpGenerator\ClassType), Object(Nette\PhpGenerator\PhpNamespace)) #3 \vendor\contributte\nextras-orm-generator\src\Generator.php(90): Contributte\Nextras\Orm\Generator\Generator\Entity\EntityGenerator->generate(Object(Contributte\Nextras\Orm\Generator\Entity\Database)) #4 \www\nextras.php(20): Contributte\Nextras\Orm\Generator\Generator->generate() #5 {main} thrown in \vendor\contributte\nextras-orm-generator\src\Entity\PhpRelDoc.php on line 132

MKI-Miro avatar Feb 20 '24 15:02 MKI-Miro

Having the same problem in PHP 8.2

Fix is to set the following to null in PhpRelDoc

private ?bool $primary = null;
private ?string $orderProperty = null;
private ?int $orderDirection = null;

I would submit a PR, but I am just benchmarking this ORM and patching the vendor directory gets me around this issue.

Also I would add FQNs to your example or add use statements.

$factory = new \Contributte\Nextras\Orm\Generator\SimpleFactory(
	new \Contributte\Nextras\Orm\Generator\Config\Impl\TogetherConfig($config),
	new \Contributte\Nextras\Orm\Generator\Analyser\Database\DatabaseAnalyser('sqlite:sqlite.db', 'root'));

Thanks for providing this package so I don't have to write code by hand.

phpfui avatar Mar 02 '24 02:03 phpfui