Skip to content

Conversation

cedric-anne
Copy link

@cedric-anne cedric-anne commented Apr 17, 2024

Fixes phpstan/phpstan#8808.

In PHP 8.2, dynamic properties were deprecated, but, as far as I understand, this change was impacting only non-static properties and was , see https://wiki.php.net/rfc/deprecate_dynamic_properties and https://github.com/nikic/php-src/blob/536d440803477b3bc4950effd357bc5572e37065/Zend/tests/dynamic_prop_deprecation.phpt#L8-L18

Also, isset/empty operations are not triggering any deprecation/warning/exception. The existing exception in the MutatingScope::setAllowedUndefinedExpression() code is therefore not correct

For instance, the following code does not trigger any deprectation/error when executed on PHP 8.2:

class Test {}

isset(Test::$undefprop);
empty(Test::$undefprop);

$test = new Test();
isset($test->undefprop);
empty($test->undefprop);

@ondrejmirtes
Copy link
Member

this change was impacting only non-static properties

"Dynamic static properties" were never a thing: https://3v4l.org/3150T

Also, isset/empty operations are not triggering any deprecation/warning/exception.

PHPStan reports a lot of things as problems that are not triggering any kind of error from PHP. For example: https://phpstan.org/r/f8f6f009-a26e-4ea3-b51c-c87e05f6d7f8

It'd be more useful if you opened a bug report or a discussion with the problem you are facing.

@cedric-anne
Copy link
Author

cedric-anne commented Apr 17, 2024

this change was impacting only non-static properties

"Dynamic static properties" were never a thing: https://3v4l.org/3150T

I agree that "dynamic properties" is not related to these error, and this is why I do not understand why the behaviour was changed for PHP >= 8.2 in the commit a6857ee, and especially by the following check that seems to indicate that "dynamic properties" are involved here:
https://github.com/phpstan/phpstan-src/blame/d9bdbc2dfe481c16d940e8c045f246991b1e7727/src/Analyser/MutatingScope.php#L3594-L3596

@ondrejmirtes
Copy link
Member

Doing #3476 in PHPStan 2.0 as promised.

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.

Access to an undefined static property

2 participants