Skip to content
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

__CLASS__ no longer has the MAGIC_CLASS flag in PHP 8.3's native AST #4841

Open
Daimona opened this issue Mar 2, 2024 · 0 comments
Open

Comments

@Daimona
Copy link
Member

Daimona commented Mar 2, 2024

I noticed that, when using PHP 8.3, phan wasn't able to recognize callables using the __CLASS__ constant, like [ __CLASS__, 'methodName' ]. Upon digging a bit, I noticed that the AST generated by php-ast is different, in that the AST_MAGIC_CONST node no longer has the MAGIC_CLASS flag:

$ php8.2 internal/dump_fallback_ast.php --php-ast-native '__CLASS__;'
AST_STMT_LIST [] #1
	0 => AST_MAGIC_CONST [MAGIC_CLASS] #1

$ php8.3 internal/dump_fallback_ast.php --php-ast-native '__CLASS__;'
AST_STMT_LIST [] #1
	0 => AST_MAGIC_CONST [] #1

Therefore, phan can no longer recognize the __CLASS__ constant, which leads to a number of issues such as not resolving callables that use it.


Some more information:

$ php8.3 --version
PHP 8.3.3-1+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Feb 15 2024 18:38:52) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.3-1+ubuntu22.04.1+deb.sury.org+1, Copyright (c), by Zend Technologies

$ php8.3 -r "echo phpversion('ast');"
1.1.1

I first spotted this notice in a continuous integration environment a month ago, but I couldn't reproduce it locally with my version of PHP 8.3. While I can't be 100% sure, I likely had 8.3.2 at the time (or 8.3.1 at most), so it might be a regression in PHP 8.3.3.

Finally, note that this still works fine when using the polyfill parser:

 $ php8.3 internal/dump_fallback_ast.php --php-ast '__CLASS__;'
AST_STMT_LIST [] #1
	0 => AST_MAGIC_CONST [MAGIC_CLASS] #1

I don't know if this is a bug in php-ast or phan, but phan is affected nonetheless.

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

No branches or pull requests

1 participant