Skip to content

Fix unsetting array item triggers unset.possiblyHookedProperty #3855

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

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Mar 6, 2025

@@ -48,7 +48,7 @@ public function processNode(Node $node, Scope $scope): array
return $errors;
}

private function canBeUnset(Node $node, Scope $scope): ?IdentifierRuleError
private function canBeUnset(Node $node, Scope $scope, bool $inArrayDimFetch = false): ?IdentifierRuleError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More logical solution is to exclude $node instanceof Node\Expr\PropertyFetch section completely out of canBeUnset recursion and just check it directly in processNode.

The other part of this about unsetting on readonly property is also wrong so we need to fix that too:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interessting..

Readonly properties cannot be unset() once they are initialized. However, it is possible to unset a readonly property prior to initialization, from the scope where the property has been declared.

https://www.php.net/manual/en/language.oop5.properties.php

@staabm staabm marked this pull request as ready for review March 6, 2025 12:45
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes
Copy link
Member

I force-pushed what I meant instead. THank you.

@staabm
Copy link
Contributor Author

staabm commented Mar 6, 2025

I see now. didn't got it in the first place.

@ondrejmirtes ondrejmirtes merged commit 2d7dd08 into phpstan:2.1.x Mar 6, 2025
406 of 417 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the bug12695 branch March 6, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsetting array item triggers unset.possiblyHookedProperty
3 participants