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

From: Date: Tue, 03 Nov 2026 11:20:41 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143272@lists.php.net to get a copy of this message
Author: Jorg Sowa (jorgsowa) Date: 2026-11-03T11:15:28+01:00 Commit: https://github.com/php/php-src/commit/e229eeac907f40227587b281f8ba5c90302955fc Raw diff: https://github.com/php/php-src/commit/e229eeac907f40227587b281f8ba5c90302955fc.diff Merge branch 'PHP-8.5' into PHP-8.6 # Conflicts: # NEWS Changed paths: A Zend/tests/first_class_callable/constexpr/trait_scope_001.phpt A Zend/tests/first_class_callable/constexpr/trait_scope_002.phpt A Zend/tests/first_class_callable/constexpr/trait_scope_003.phpt A Zend/tests/first_class_callable/constexpr/trait_scope_004.phpt A Zend/tests/first_class_callable/constexpr/trait_scope_005.phpt A Zend/tests/first_class_callable/constexpr/trait_scope_006.phpt M NEWS M Zend/zend_ast.c Diff: diff --git a/NEWS b/NEWS index 1fca9d7c8898..d0b8e04c39a6 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,9 @@ PHP NEWS (Lazizbek Ergashev) . Fixed bug GH-23911 (Don't use static closure cache when called_scope diverges). (Roman Ondráček) + . Fixed first-class callables to static methods in trait constant + expressions resolving to the method of the first using class and + bypassing visibility checks. (Jorg Sowa) - CLI: . Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work). diff --git a/Zend/tests/first_class_callable/constexpr/trait_scope_001.phpt b/Zend/tests/first_class_callable/constexpr/trait_scope_001.phpt new file mode 100644 index 000000000000..8199b47afa97 --- /dev/null +++ b/Zend/tests/first_class_callable/constexpr/trait_scope_001.phpt @@ -0,0 +1,18 @@ +--TEST-- +FCC for self:: static method in trait default argument is resolved per using class +--FILE-- +<?php + +trait T { + public static function make($f = self::who(...)) { return $f(); } +} +class A { use T; public static function who() { return 'A'; } } +class B { use T; public static function who() { return 'B'; } } + +echo A::make(), PHP_EOL; +echo B::make(), PHP_EOL; + +?> +--EXPECT-- +A +B diff --git a/Zend/tests/first_class_callable/constexpr/trait_scope_002.phpt b/Zend/tests/first_class_callable/constexpr/trait_scope_002.phpt new file mode 100644 index 000000000000..5390f6337a52 --- /dev/null +++ b/Zend/tests/first_class_callable/constexpr/trait_scope_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +FCC for parent:: static method in trait default argument is resolved per using class +--FILE-- +<?php + +class P1 { public static function who() { return 'P1'; } } +class P2 { public static function who() { return 'P2'; } } +trait T { + public static function make($f = parent::who(...)) { return $f(); } +} +class A extends P1 { use T; } +class B extends P2 { use T; } + +echo A::make(), PHP_EOL; +echo B::make(), PHP_EOL; + +?> +--EXPECT-- +P1 +P2 diff --git a/Zend/tests/first_class_callable/constexpr/trait_scope_003.phpt b/Zend/tests/first_class_callable/constexpr/trait_scope_003.phpt new file mode 100644 index 000000000000..ae63777392ba --- /dev/null +++ b/Zend/tests/first_class_callable/constexpr/trait_scope_003.phpt @@ -0,0 +1,23 @@ +--TEST-- +FCC for self:: static method in trait constant and property default is resolved per using class +--FILE-- +<?php + +trait T { + const C = self::who(...); + public $p = self::who(...); +} +class A { use T; public static function who() { return 'A'; } } +class B { use T; public static function who() { return 'B'; } } + +echo (A::C)(), PHP_EOL; +echo (B::C)(), PHP_EOL; +echo ((new A)->p)(), PHP_EOL; +echo ((new B)->p)(), PHP_EOL; + +?> +--EXPECT-- +A +B +A +B diff --git a/Zend/tests/first_class_callable/constexpr/trait_scope_004.phpt b/Zend/tests/first_class_callable/constexpr/trait_scope_004.phpt new file mode 100644 index 000000000000..da1608e2d918 --- /dev/null +++ b/Zend/tests/first_class_callable/constexpr/trait_scope_004.phpt @@ -0,0 +1,22 @@ +--TEST-- +FCC for self:: private static method in trait default argument does not leak to other using classes +--FILE-- +<?php + +trait T { + public static function make($f = self::who(...)) { return $f(); } +} +class A { use T; private static function who() { return 'A'; } } +class B { use T; } + +echo A::make(), PHP_EOL; +try { + B::make(); +} catch (Error $e) { + echo $e::class, ": ", $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +A +Error: Call to undefined method B::who() diff --git a/Zend/tests/first_class_callable/constexpr/trait_scope_005.phpt b/Zend/tests/first_class_callable/constexpr/trait_scope_005.phpt new file mode 100644 index 000000000000..50382a449939 --- /dev/null +++ b/Zend/tests/first_class_callable/constexpr/trait_scope_005.phpt @@ -0,0 +1,22 @@ +--TEST-- +FCC for named class private static method in trait default argument checks visibility per using class +--FILE-- +<?php + +trait T { + public static function make($f = A::who(...)) { return $f(); } +} +class A { use T; private static function who() { return 'A'; } } +class B { use T; } + +echo A::make(), PHP_EOL; +try { + B::make(); +} catch (Error $e) { + echo $e::class, ": ", $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +A +Error: Call to private method A::who() from scope B diff --git a/Zend/tests/first_class_callable/constexpr/trait_scope_006.phpt b/Zend/tests/first_class_callable/constexpr/trait_scope_006.phpt new file mode 100644 index 000000000000..4ffb56841caa --- /dev/null +++ b/Zend/tests/first_class_callable/constexpr/trait_scope_006.phpt @@ -0,0 +1,20 @@ +--TEST-- +FCC for named class public static method in trait default argument is shared across using classes +--FILE-- +<?php + +trait T { + public static function make($f = A::who(...)) { return $f(); } +} +class A { use T; public static function who() { return 'A'; } } +class B { use T; } + +echo A::make(), PHP_EOL; +echo B::make(), PHP_EOL; +echo A::make(), PHP_EOL; + +?> +--EXPECT-- +A +A +A diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 84290d1520ad..5891974946d6 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1324,7 +1324,11 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner( } } - ZEND_MAP_PTR_SET(fcc_ast->fptr, fptr); + /* The AST may be shared between scopes (e.g. via traits), so only cache scope-independent results. */ + if ((ast->child[0]->attr >> ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT) == ZEND_FETCH_CLASS_DEFAULT + && (fptr->common.fn_flags & ZEND_ACC_PUBLIC)) { + ZEND_MAP_PTR_SET(fcc_ast->fptr, fptr); + } } break;

« previous php.cvs (#143272) next »