-
Notifications
You must be signed in to change notification settings - Fork 506
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
Hooked properties cannot be unset() #3842
Conversation
This pull request has been marked as ready for review. |
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.
One more thing - if we're on PHP 8.4+ (phpVersion::supportsPropertyHooks), and the property is not final, and the declaring class is not final, and the property is not private, report a similar error even if the property does not have hooks. Preferably with a different explaining error message. Because a subclass might create a hooked declaration for the same property.
We're already doing a similar thing here (accessing/writing a property that might be hooked in a subclass can throw any exception):
phpstan-src/src/Analyser/NodeScopeResolver.php
Lines 4317 to 4331 in 3d0a658
$declaringClass = $propertyReflection->getDeclaringClass(); | |
if (!$propertyReflection->hasHook($hookName)) { | |
if ( | |
$propertyReflection->isPrivate() | |
|| $propertyReflection->isFinal()->yes() | |
|| $declaringClass->isFinal() | |
) { | |
return []; | |
} | |
if ($this->implicitThrows) { | |
return [ThrowPoint::createImplicit($scope, $propertyFetch)]; | |
} | |
return []; |
this sounds like a edge case which should only be reported via a opt-in flag..? |
while testing I found https://phpstan.org/r/0299facc-d23d-4ed8-9567-e1c7c8c30536 which I think should not report a error on line 9 on PHP 8.4, right? |
if ( | ||
!$propertyReflection->isPrivate() | ||
&& !$propertyReflection->isFinal()->yes() | ||
&& !$propertyReflection->getDeclaringClass()->isFinal() | ||
) { |
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 also though about adding
public function isHookedInSubclass(): TrinaryLogic {
if (
!$this->isPrivate()
&& !$this->isFinal()->yes()
&& !$this->getDeclaringClass()->isFinal()
) {
return TrinaryLogic::createMaybe();
}
return TrinaryLogic::createNo();
}
to PhpPropertyReflection
. wdyt?
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.
Not needed right now :) I'd have to this about that more.
Thank you! |
refs phpstan/phpstan#12336