Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Validator] check for __get method existence if property is uninitialized#35546
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
164ab11 to560e2c8Compare| returnnull; | ||
| if (\PHP_VERSION_ID >=70400 &&$reflProperty->hasType() && !$reflProperty->isInitialized($object)) { | ||
| // There is no way to check if a property has been unset or it is uninitialized. | ||
| // When trying to access an uninitialized property, __get method is triggered in PHP 7.4.0, but not in 7.4.1+. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Does this mean that there was a bug in PHP 7.4.0 and__get() should never have been called? In this case, I am not convinced that we should do anything here as the behaviour is inline with what happens in PHP 7.4.1+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
see alsohttps://3v4l.org/8E83P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
or should we call__get() directly?
greedyivanFeb 1, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There is a discussionPHP Bug # 78904.
This is a PHP related problem, I think. Framework should not implement any hack for this. ProxyManager and others are currently not compatible with PHP 7.4.1+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
__getmust be called when accessing a property if the property has been explicitly unset, but not if it is uninitialized.
On the other sideReflectionProperty::isInitialized is returning false for both situations and there is nosafe way to distinguish one state from the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ThehasType has been added as if the property is not typed, no additional check should be made.
I think that\Error is too generic. Per typed properties RFC\TypeError is raised in case of access an uninitialized non-nullable typed property.
greedyivanFeb 1, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The
hasTypehas been added as if the property is not typed, no additional check should be made.
Agreed.hasType is just a zero cost check.
I think that
\Erroris too generic. Per typed properties RFC\TypeErroris raised in case of access an uninitialized non-nullable typed property.
Don't trust docs blindly.
greedyivanFeb 1, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
According that, additional tests should be added.
- typed uninitialized propery with no unset in constructor and with __get method.
This test would validate a correct way of\Error catching. In case if it will be changed to\TypeError in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I've just added a check. Too bad that RFC is not respected about the\TypeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Too bad that RFC is not respected about the
\TypeError
Doc Bug #79206
Let's see, it is a doc bug or not.
xabbuh left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I am strongly against merging this as is as this would now work differently than how PHP behaves in 7.4.1+. I suggest to wait until a final decision has been made for PHP and then decide whether or not we have to adapt the validator code.
greedyivan commentedFeb 1, 2020
Here we trying to solve one special case, when typed property is Only difference with 7.4.0 that this magic method was invoked in uninitialized state also. This is normal (invoking |
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Reasonable, isn't it?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
alekitto commentedFeb 3, 2020
Yes, i've corrected the comments. |
fabpot commentedFeb 3, 2020
Thank you@alekitto. |
…s uninitialized (alekitto)This PR was merged into the 3.4 branch.Discussion----------[Validator] check for __get method existence if property is uninitialized| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#35544| License | MITResolve bug#35544.On PHP 7.4, check if object implements `__get` magic method if property is reported as uninitialized before returning null.Commits-------427bc3a [Validator] try to call __get method if property is uninitialized
Resolve bug#35544.
On PHP 7.4, check if object implements
__getmagic method if property is reported as uninitialized before returning null.