[php-src] master: Merge branch 'PHP-8.6'

From: Date: Thu, 05 Nov 2026 21:17:44 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143358@lists.php.net to get a copy of this message
Author: Jorg Sowa (jorgsowa) Date: 2026-11-05T22:06:36+01:00 Commit: https://github.com/php/php-src/commit/0012f1a01287878285119b9d690b9d5b8d6650e5 Raw diff: https://github.com/php/php-src/commit/0012f1a01287878285119b9d690b9d5b8d6650e5.diff Merge branch 'PHP-8.6' # Conflicts: # NEWS Changed paths: A Zend/tests/assert/ast_export_dynamic_class_const.phpt M Zend/zend_ast.c Diff: diff --git a/Zend/tests/assert/ast_export_dynamic_class_const.phpt b/Zend/tests/assert/ast_export_dynamic_class_const.phpt new file mode 100644 index 000000000000..43a5e31c714d --- /dev/null +++ b/Zend/tests/assert/ast_export_dynamic_class_const.phpt @@ -0,0 +1,50 @@ +--TEST-- +AST export of dynamic class constant fetches +--INI-- +zend.assertions=1 +--FILE-- +<?php + +$tests = [ + fn() => assert(false && C::FOO), + fn() => assert(false && C::list), + fn() => assert(false && C::class), + fn() => assert(false && C::{$x}), + fn() => assert(false && C::{FOO}), + fn() => assert(false && C::{foo()}), + fn() => assert(false && C::{$a . $b}), + fn() => assert(false && C::{1}), + fn() => assert(false && C::{'foo'}), + fn() => assert(false && C::{'a b'}), + fn() => assert(false && C::{''}), + fn() => assert(false && C::{'class'}), + fn() => assert(false && C::{'CLASS'}), + fn() => assert(false && $o::{$x}), + fn() => assert(false && static::{$x}), +]; + +foreach ($tests as $test) { + try { + $test(); + } catch (AssertionError $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} + +?> +--EXPECT-- +AssertionError: assert(false && C::FOO) +AssertionError: assert(false && C::list) +AssertionError: assert(false && C::class) +AssertionError: assert(false && C::{$x}) +AssertionError: assert(false && C::{FOO}) +AssertionError: assert(false && C::{foo()}) +AssertionError: assert(false && C::{$a . $b}) +AssertionError: assert(false && C::{1}) +AssertionError: assert(false && C::foo) +AssertionError: assert(false && C::{'a b'}) +AssertionError: assert(false && C::{''}) +AssertionError: assert(false && C::{'class'}) +AssertionError: assert(false && C::{'CLASS'}) +AssertionError: assert(false && $o::{$x}) +AssertionError: assert(false && static::{$x}) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index b5caac7afc22..34d68f481028 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1887,6 +1887,24 @@ static ZEND_COLD bool zend_ast_valid_var_name(const char *s, size_t len) return true; } +static ZEND_COLD void zend_ast_export_class_const_name(smart_str *str, zend_ast *ast, int indent) +{ + if (ast->kind == ZEND_AST_ZVAL) { + const zval *zv = zend_ast_get_zval(ast); + + /* A bare "class" would turn the dynamic fetch into a class name fetch. */ + if (Z_TYPE_P(zv) == IS_STRING + && zend_ast_valid_var_name(Z_STRVAL_P(zv), Z_STRLEN_P(zv)) + && !zend_string_equals_ci(Z_STR_P(zv), ZSTR_KNOWN(ZEND_STR_CLASS))) { + smart_str_append(str, Z_STR_P(zv)); + return; + } + } + smart_str_appendc(str, '{'); + zend_ast_export_ex(str, ast, 0, indent); + smart_str_appendc(str, '}'); +} + static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int indent) { if (ast->kind == ZEND_AST_ZVAL) { @@ -2725,7 +2743,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio case ZEND_AST_CLASS_CONST: zend_ast_export_ns_name_or_expression(str, ast->child[0], 0, indent); smart_str_appends(str, "::"); - zend_ast_export_name(str, ast->child[1], 0, indent); + zend_ast_export_class_const_name(str, ast->child[1], indent); break; case ZEND_AST_CLASS_NAME: if (ast->child[0] == NULL) {

« previous php.cvs (#143358) next »