Feature request
In php, object properties can be accessed using the syntax $obj->{$name} where $name is a string (or integer or float it seems... Not sure what the exact rules are. Possibly, some numeric strings are automatically converted to integers/floats, etc.) Properties can also be accessed using the syntax $obj->somename but in this case, there are stricter rules about the format of the name. somename must be compatible with php's rules and cannot start with or contain certain special characters such as $ or ..
Given the above, for some property names, there are two equivalent ways of accessing the property. Take the example n. Given an object $ojb, $obj->n is equivalent to $obj->{'n'}.
Phpstan doesn't appear to understand this equivalence in all contexts, which can lead to some false positives. See for example:
https://phpstan.org/r/a4747b5b-1a1d-4cac-9e5d-00eb4ffafaef
In the first test, dead code is not identified, and in the second, type narrowing when accessing a property one way is not applied when accessing it another.
It would be great if phpstan's understanding of this equivalence could be made more robust.
Did PHPStan help you today? Did it make you happy in any way?
Yes!
Feature request
In php, object properties can be accessed using the syntax
$obj->{$name}where$nameis a string (or integer or float it seems... Not sure what the exact rules are. Possibly, some numeric strings are automatically converted to integers/floats, etc.) Properties can also be accessed using the syntax$obj->somenamebut in this case, there are stricter rules about the format of the name.somenamemust be compatible with php's rules and cannot start with or contain certain special characters such as$or..Given the above, for some property names, there are two equivalent ways of accessing the property. Take the example
n. Given an object$ojb,$obj->nis equivalent to$obj->{'n'}.Phpstan doesn't appear to understand this equivalence in all contexts, which can lead to some false positives. See for example:
https://phpstan.org/r/a4747b5b-1a1d-4cac-9e5d-00eb4ffafaef
In the first test, dead code is not identified, and in the second, type narrowing when accessing a property one way is not applied when accessing it another.
It would be great if phpstan's understanding of this equivalence could be made more robust.
Did PHPStan help you today? Did it make you happy in any way?
Yes!