doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.95k stars 2.52k forks source link

DynamicProperties and collection for PHP > 8.2 #11747

Closed jonathangreco closed 9 hours ago

jonathangreco commented 10 hours ago

Hi everyone,

I noticed in the official documentation (both for the current version and the upcoming version 4) that collections are still being instantiated dynamically within constructors.

With PHP 8.2 and above, this behavior triggers deprecation warnings, and it will result in fatal errors starting with PHP 9.0.

It seems there are no official guidelines or workarounds addressing this issue yet. Is this behavior intentional? Suggestions for Improvement

Temporary Solution:

Add the #[AllowDynamicProperties] attribute to the top of each entity where dynamic instantiation of collections occurs, as a quick fix.

Long-term Solution:

Update constructors on those documentation to reflect the new PHP 8 best practices

public function __construct(
        private ArrayCollection $myClass = new ArrayCollection(),
    ){}

Looking forward to hearing thoughts or suggested best practices from the community!

derrabus commented 9 hours ago

I noticed in the official documentation (both for the current version and the upcoming version 4) that collections are still being instantiated dynamically within constructors.

Sorry, where exactly does the documentation state that you should not declare the properties that you assign to?