[php-src] master: Merge branch 'PHP-8.6'
| From: | Jorg Sowa | Date: | Tue, 03 Nov 2026 11:20:43 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143273@lists.php.net to get a copy of this message | ||
Author: Jorg Sowa (jorgsowa)
Date: 2026-11-03T12:13:06+01:00
Commit: https://github.com/php/php-src/commit/4b41f2dd39f51bd5ee20956696b352ac11afadac
Raw diff: https://github.com/php/php-src/commit/4b41f2dd39f51bd5ee20956696b352ac11afadac.diff
Merge branch '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 Zend/zend_ast.c
Diff:
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;