Skip to content

Conversation

@TysonAndre
Copy link
Collaborator

Fixes #109

This also makes PHP 7.4 emulate the old behavior (AST_CLASS_CONST) for versions 50 and 60.

Tests pass with a local PHP 7.4 installation

@TysonAndre
Copy link
Collaborator Author

TysonAndre commented Jan 27, 2019

The merge conflicts were fixed, tests in php 7.4-dev are still passing locally

EDIT: Added missing break after the merge conflicts were fixed, and restored newline at the end of a test file

@TysonAndre TysonAndre force-pushed the fix-class-const branch 2 times, most recently from 7d0dcd1 to c117795 Compare January 27, 2019 15:42
ast.c Outdated
// Convert to an AST_CLASS_NAME instead. The opposite of the work done in the ZEND_AST_CLASS_NAME case.
zend_ast *const_name_ast = ast->child[1];
if (const_name_ast->kind != ZEND_AST_ZVAL) {
break; // Currently impossible
Copy link
Owner

Choose a reason for hiding this comment

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

If it's impossible, we should drop the check. zend_ast_get_zval contains an assertion that checks this. Even better would be to use zend_ast_get_str() to directly get at the zend_string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

php > var_export([]::class);

Fatal error: Cannot use ::class with dynamic class name in php shell code on line 1

Okay, it's possible (I just didn't test every possible edge case) - that's a runtime error, not a syntax error

Copy link
Collaborator Author

@TysonAndre TysonAndre Jan 27, 2019

Choose a reason for hiding this comment

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

Okay, I'm going to have to report a bug with php 7.4-dev debug ZTS on bugs.php.net:

php > var_export((2)::class);
php: /path/to/php-src/Zend/zend_ast.h:298: zend_ast_get_str: Assertion `zval_get_type(&(*(zv))) == 6' failed.
[1]    4949 abort      php -a

Copy link
Collaborator Author

@TysonAndre TysonAndre Jan 27, 2019

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It turns out that I was mistaken and it indeed something I should check for (I tried 2::class the first time but not (2)::class)

Fixes nikic#109

Tests pass with a local PHP 7.4 installation
@TysonAndre
Copy link
Collaborator Author

All review comments have been addressed, this is ready for another look. The new tests continue to pass in PHP 7.4.

Note that the flags on the AST_ARRAY of []::class are inconsistent, but that's very low priority

ast.c Outdated
if (state->version >= 70) {
// Convert to an AST_CLASS_NAME instead. This is the opposite of the work done in the ZEND_AST_CLASS_NAME case.
zend_ast *const_name_ast = ast->child[1];
if (const_name_ast->kind != ZEND_AST_ZVAL) {
Copy link
Owner

Choose a reason for hiding this comment

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

While the class can be an expression, the constant name can't be (we don't have Foo::{$bar} in PHP), so these checks at least can be replaced with zend_ast_get_str.

} else {
// e.g. []::class (not a parse error, but a runtime error)
ast_to_zval(&class_name_zval, class_name_ast, state);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't ast_to_zval here work for both branches?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It didn't create the ast\Node when I tried that, probably because the parent kind or position was wrong.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah yeah, I guess it will just convert it to a simple value. In that case it's fine.

@nikic nikic merged commit fb1be83 into nikic:master Jan 30, 2019
@nikic
Copy link
Owner

nikic commented Jan 30, 2019

Thanks!

@TysonAndre TysonAndre deleted the fix-class-const branch May 11, 2019 16:13
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.

2 participants