-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
add check for uninitialized property, and force reflection if type is… #1375
Conversation
Awesome, this looks good 👍 I suspected it would have been more work. |
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.
Hello @re2bit!
Thank you for your work! :) It looks good, I left few comments.
In general as forcing Reflection Access might slow down application I would try to limit possible cases when possible - I found that with PHP8.0 has also ReflectionProperty::hasDefaultValue()
method that might help to avoid forcing usage of reflection to minimum - what do you think about it?
Best!
$this->forceReflectionAccess = $class->isInternal() | ||
|| $reflectionProperty->isStatic(); | ||
$this->hasType = PHP_VERSION_ID >= 70400 | ||
&& method_exists($reflectionProperty, 'hasType') |
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.
Do we need additional check if method exists? according to docs it should be available since PHP 7.4 - so I would remove additional checks.
$ref = $this->propertyReflectionCache[$metadata->class][$metadata->name] ?? null; | ||
if (null === $ref) { | ||
$ref = new \ReflectionProperty($metadata->class, $metadata->name); | ||
$ref->setAccessible(true); | ||
$this->propertyReflectionCache[$metadata->class][$metadata->name] = $ref; | ||
} | ||
|
||
if (PHP_VERSION_ID >= 70400 && !$ref->isInitialized($object)) { |
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.
Should it be executed also for the cases when $metadata->forceReflectionAccess
is set to true, but $context->getShouldSerializeUnitializedAsNull()
will return false?
Introducing |
I am closing this PR due to inactivity. |
Draft for Discussion of #1367