-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typed property must not be accessed before initialization #7944
Comments
This is relatively normal: the |
That totally makes sense. However... what's the recommended route forward here? Obviously you don't want the |
@oojacoboo but technically |
Yea, had a good discussion on Slack about this. I suspect that many other people will run into this issue as PHP 7.4 begins to be adopted more and people start typing their properties. We'll just use |
I have the same issue, ATM i'm adopting the |
Would be nice to have a different solution than setting nullables everywhere. |
Updating doctrine/persistence to 1.3.6 will fix this issue. |
Unfortunately, even with the updates to // Entity with this $oid after deletion treated as NEW, even if the $oid
// is obtained by a new entity because the old one went out of scope.
//$this->entityStates[$oid] = self::STATE_NEW;
if ( ! $class->isIdentifierNatural()) {
$class->reflFields[$class->identifier[0]]->setValue($entity, null);
} I've filed this issue: #7999 |
using this: "name": "doctrine/persistence", "version": "1.3.6", |
Can the property just be Deletion is an interesting scenario. Technically, unless using soft-delete, that object shouldn't really exist anymore, and certainly not the ID. I can see how it'd be useful to use an object after deletion though. |
My error:
My solution - add next method to the class:
|
it doesn't |
What about properties where you can't set the default value, like in associations that use collection? Object cannot be a default value, and nullable makes no sense here. This example: class Entity {
/**
* @ORM\OneToMany(targetEntity="Other")
* @var Collection|Other[]
*/
protected $friends;
public function __construct() {
$this->friends = new ArrayCollection();
}
} used to be the proper way to initialize collections, but now if you add PHP7.4 property type hints ( And that's not the only example, what about custom Doctrine types that use some object to hold the value? |
Proxy initialization does set collections? What doesn't work (and also didn't work in the past) in the 2.x series is "friend objects", but otherwise proxy initialization does populate their associations. This is the broken behavior (also pre-php-7.4): class Thing
{
private $id;
private $lazyField;
function equals(self $other) {
return $other->lazyField->equals($this->lazyField); // call to `equals` on `null` happening here
}
} |
@Ocramius That's partially right. But, you don't need the call to |
Interesting, for some reason I have this issue only in our Jenkins test build but can't replicate it locally. I'll investigate further. |
@oojacoboo yes, I made the example to show that the method call will lead to a crash: much harder to notice if I used |
Alright, investigation concluded; when clearing cache on Jenkins no APP_ENV was defined so it cleared the default, but we needed other envs cleared. This lead to old metadata being used from cache and in those Doctrine didn't even know about some of the fields, skipping the initialization. Sorry, my mistake. |
I had exactly the same problem, only happening on the web server and not in local environment, and the cause was :
The worst thing was, after triggering the error, I had to delete the session manually in the server in the /var/lib/php/sessions folder because Symfony couldn't access to the session anymore which completely stuck the website for the current browser. I first tried to "override" the __sleep() method as answered before, but even if the error was not triggered, my attribute was empty and that's not what I wanted. My solution was to clone, then empty the collection with a ->clear() method after cloning the object, then settting it with the add() method. I think the heart of the problem is this __sleep() method when objects with ArrayCollection attributes are cloned from the session. I still don't understand why the bug didn't happen with php 7.4.9 and 7.4.1 in a local environment but happened with 7.4.3 on the server... The error is the same as described here but they closed it : symfony/symfony#35574 |
See doctrine/orm#7944 (comment) for more information.
See doctrine/orm#7944 (comment) for more information.
See doctrine/orm#7944 (comment) for more information.
See doctrine/orm#7944 (comment) for more information.
I am getting the same issue with quite new libraries... doctrine/annotations 1.13.2 |
Bug Report
Summary
doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:634
Seems to be an issue with reflection attempting to access typed properties.
The text was updated successfully, but these errors were encountered: