Skip to content

Fix class name FQN when AST dumping new and class const #9462

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) {

zend_class_entry *zend_ast_fetch_class(zend_ast *ast, zend_class_entry *scope)
{
return zend_fetch_class_with_scope(zend_ast_get_str(ast), ast->attr | ZEND_FETCH_CLASS_EXCEPTION, scope);
return zend_fetch_class_with_scope(zend_ast_get_str(ast), (ast->attr >> ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT) | ZEND_FETCH_CLASS_EXCEPTION, scope);
}

ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *scope)
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9736,8 +9736,8 @@ static void zend_compile_const_expr_class_const(zend_ast **ast_ptr) /* {{{ */
zend_string_release_ex(class_name, 0);
if (tmp != class_name) {
zval *zv = zend_ast_get_zval(class_ast);

ZVAL_STR(zv, tmp);
class_ast->attr = ZEND_NAME_FQ;
}
}

Expand Down Expand Up @@ -9832,7 +9832,7 @@ static void zend_compile_const_expr_new(zend_ast **ast_ptr)
zval *class_ast_zv = zend_ast_get_zval(class_ast);
zval_ptr_dtor_nogc(class_ast_zv);
ZVAL_STR(class_ast_zv, class_name);
class_ast->attr = fetch_type;
class_ast->attr = fetch_type << ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT;
}

static void zend_compile_const_expr_args(zend_ast **ast_ptr)
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
#define ZEND_NAME_NOT_FQ 1
#define ZEND_NAME_RELATIVE 2

/* ZEND_FETCH_ flags in class name AST of new const expression must not clash with ZEND_NAME_ flags */
#define ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT 2

#define ZEND_TYPE_NULLABLE (1<<8)

#define ZEND_ARRAY_SYNTAX_LIST 1 /* list() */
Expand Down
39 changes: 39 additions & 0 deletions ext/reflection/tests/gh9447.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
ReflectionProperty::get/setValue() on internal static property
--FILE--
<?php

namespace App;

use SomewhereElse\Qux;

class Foo
{
public function bar(
$a = Bar::BAZ,
$b = new Bar(),
$c = new parent(),
$d = new self(),
$e = new namespace\Bar(),
$f = new Qux(),
$g = new namespace\Qux(),
$i = new \Qux(),
) {}
}

$r = new \ReflectionMethod(Foo::class, 'bar');

foreach ($r->getParameters() as $p) {
echo $p, "\n";
}

?>
--EXPECT--
Parameter #0 [ <optional> $a = \App\Bar::BAZ ]
Parameter #1 [ <optional> $b = new \App\Bar() ]
Parameter #2 [ <optional> $c = new parent() ]
Parameter #3 [ <optional> $d = new self() ]
Parameter #4 [ <optional> $e = new \App\Bar() ]
Parameter #5 [ <optional> $f = new \SomewhereElse\Qux() ]
Parameter #6 [ <optional> $g = new \App\Qux() ]
Parameter #7 [ <optional> $i = new \Qux() ]