-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Validator incompatibility with ProxyManager #35544
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
Comments
Would you mind sending a PR please? |
I want to clarify how this bug differs from #35454 Originally, there was an object class Foo
{
/**
* @Assert\NotBlank()
*/
public int $bar;
} If a property is accessed in this initial uninitialized state, PHP throws an error:
Thus, when the validator tried to check the value and called But that fix broke one special case. If there is an object class Foo
{
/**
* @Assert\NotBlank()
*/
public int $bar;
public function __construct()
{
unset($this->bar);
}
public function __get($name)
{
return 42;
}
} And a property is accessed in that This issue is about that. But there is one special case related with PHP 7.4.0 and 7.4.1+. class Foo
{
/**
* @Assert\NotBlank()
*/
public int $bar;
public function __get($name)
{
return 42;
}
} This code will trigger error in 7.4.1+, but not in 7.4.0 ( Therefore, a full implementation should only consider the latest version of PHP. There is no reason to implement a behavior that was found to be erroneous and fixed in future versions. Recap |
…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 | MIT Resolve 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
Symfony version(s) affected: 5.0.4
Description
When trying to validate a value holder proxy generated with ocramius/proxy-manager, all the public properties will be unset at construction.
This results in
ReflectionProperty::isInitialized()
returning false as clearly documented here.PR #35532 introduced check on
isInitialized
returning null instead of firing an__get
call.Possible Solution
Check if
__get
method exists before blindly returning null, as per rfc "reads from uninitialized properties will generate a TypeError unless __get() is defined".The text was updated successfully, but these errors were encountered: