Skip to content

Commit d36874d

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix class name FQN when AST dumping new and class const
2 parents f7d426c + 2cfb028 commit d36874d

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) {
495495

496496
zend_class_entry *zend_ast_fetch_class(zend_ast *ast, zend_class_entry *scope)
497497
{
498-
return zend_fetch_class_with_scope(zend_ast_get_str(ast), ast->attr | ZEND_FETCH_CLASS_EXCEPTION, scope);
498+
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);
499499
}
500500

501501
static zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *ast, zend_class_entry *scope, bool *short_circuited_ptr)

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9812,8 +9812,8 @@ static void zend_compile_const_expr_class_const(zend_ast **ast_ptr) /* {{{ */
98129812
zend_string_release_ex(class_name, 0);
98139813
if (tmp != class_name) {
98149814
zval *zv = zend_ast_get_zval(class_ast);
9815-
98169815
ZVAL_STR(zv, tmp);
9816+
class_ast->attr = ZEND_NAME_FQ;
98179817
}
98189818
}
98199819

@@ -9908,7 +9908,7 @@ static void zend_compile_const_expr_new(zend_ast **ast_ptr)
99089908
zval *class_ast_zv = zend_ast_get_zval(class_ast);
99099909
zval_ptr_dtor_nogc(class_ast_zv);
99109910
ZVAL_STR(class_ast_zv, class_name);
9911-
class_ast->attr = fetch_type;
9911+
class_ast->attr = fetch_type << ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT;
99129912
}
99139913

99149914
static void zend_compile_const_expr_args(zend_ast **ast_ptr)

Zend/zend_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,9 @@ ZEND_API zend_string *zend_type_to_string(zend_type type);
939939
#define ZEND_NAME_NOT_FQ 1
940940
#define ZEND_NAME_RELATIVE 2
941941

942+
/* ZEND_FETCH_ flags in class name AST of new const expression must not clash with ZEND_NAME_ flags */
943+
#define ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT 2
944+
942945
#define ZEND_TYPE_NULLABLE (1<<8)
943946

944947
#define ZEND_ARRAY_SYNTAX_LIST 1 /* list() */

ext/reflection/tests/gh9447.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-9447: Invalid class FQN emitted by AST dump for new and class constants in constant expressions
3+
--FILE--
4+
<?php
5+
6+
namespace App;
7+
8+
use SomewhereElse\Qux;
9+
10+
class Foo
11+
{
12+
public function bar(
13+
$a = Bar::BAZ,
14+
$b = new Bar(),
15+
$c = new parent(),
16+
$d = new self(),
17+
$e = new namespace\Bar(),
18+
$f = new Qux(),
19+
$g = new namespace\Qux(),
20+
$i = new \Qux(),
21+
) {}
22+
}
23+
24+
$r = new \ReflectionMethod(Foo::class, 'bar');
25+
26+
foreach ($r->getParameters() as $p) {
27+
echo $p, "\n";
28+
}
29+
30+
?>
31+
--EXPECT--
32+
Parameter #0 [ <optional> $a = \App\Bar::BAZ ]
33+
Parameter #1 [ <optional> $b = new \App\Bar() ]
34+
Parameter #2 [ <optional> $c = new parent() ]
35+
Parameter #3 [ <optional> $d = new self() ]
36+
Parameter #4 [ <optional> $e = new \App\Bar() ]
37+
Parameter #5 [ <optional> $f = new \SomewhereElse\Qux() ]
38+
Parameter #6 [ <optional> $g = new \App\Qux() ]
39+
Parameter #7 [ <optional> $i = new \Qux() ]

0 commit comments

Comments
 (0)