-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Typed property /w magic __get cannot be uninitialized #9389
Comments
That message indeed look fishy. I'm not even sure if the type check is intentional. I'll check the RFC and implementation later. |
Meant to comment this on the other issue. |
Yes, the wrong message issue is reported in #9388.
The However there is also:
Currently this is not true. If property is "defined, uninitialized but not unset", |
Ah right. That makes sense.
Yes, but as you mentioned it was changed deliberately after the RFC has been voted on. f1848a4 IMO unsetting typed properties and keeping them unset sounds like a bad idea, as now any property access might succeed throw just one dubious method call later (with this behavior, that is). The inconsistency with So personally I'd rather see that gone, but others might disagree. According to f1848a4 this was only added as a workaround for ORMs anyway.
I don't quite understand why that would be needed though. |
One example why it is needed for ORM: class defined by an user:
is extended (on runtime) like:
by ORM framework and evaluated (using eval or more often saved into some cache dir and included to be cacheable). The This allows the If ORM manager wants to use some magic ORM magic, it creates the In atk4/data framework we have things called model and entity. They both share the same class, an entity instance is created by cloning model instance. Some entity properties are desired to defined once for all entities and parent model, thus we unset them in https://github.com/atk4/data/blob/c6bfad1acb588f850f93bc5773aede2a832e23c1/src/Model.php#L395. Given both examples would be impossible when typed properties would not be possible to unset, I belive, and thanks got to f1848a4, all (mutable) properties must be allowed to be unset. |
One usecase/example of this issue - https://github.com/atk4/data/blob/5.0.0/src/Model/Scope.php#L67 - the |
Description
demo: https://3v4l.org/lDeXi
Currently, typed property can be "almost uninitialized" by
unset()
.But doing such uninitialization unsets the property and allows magic __get to kick in. This is expected and discussed in #9021.
Because of this, non-readonly typed property cannot be uninitialized properly. This is an issue in cases when the same object is to be restored, reused or cleaned.
To allow an object state to be restored/uninitialized correctly, I propose to add
ReflectionProperty::setUninitialized()
method and backport it into PHP 8.0 and above.The text was updated successfully, but these errors were encountered: