Hooked properties cannot be unset()#3842
Conversation
|
This pull request has been marked as ready for review. |
ondrejmirtes
left a comment
There was a problem hiding this comment.
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
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.
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.
Not needed right now :) I'd have to this about that more.
|
Thank you! |
refs phpstan/phpstan#12336