mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix class name FQN when AST dumping new and class const
This commit is contained in:
commit
d36874d002
4 changed files with 45 additions and 3 deletions
|
@ -495,7 +495,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);
|
||||
}
|
||||
|
||||
static zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *ast, zend_class_entry *scope, bool *short_circuited_ptr)
|
||||
|
|
|
@ -9812,8 +9812,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9908,7 +9908,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)
|
||||
|
|
|
@ -939,6 +939,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() */
|
||||
|
|
39
ext/reflection/tests/gh9447.phpt
Normal file
39
ext/reflection/tests/gh9447.phpt
Normal file
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
GH-9447: Invalid class FQN emitted by AST dump for new and class constants in constant expressions
|
||||
--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() ]
|
Loading…
Add table
Add a link
Reference in a new issue