[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Jorg Sowa | Date: | Wed, 28 Oct 2026 21:28:18 +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-142896@lists.php.net to get a copy of this message | ||
Author: Jorg Sowa (jorgsowa)
Date: 2026-10-28T22:24:51+01:00
Commit: https://github.com/php/php-src/commit/2290496110dba75dcabb9af1f137781153694c56
Raw diff: https://github.com/php/php-src/commit/2290496110dba75dcabb9af1f137781153694c56.diff
Merge branch 'PHP-8.5' into PHP-8.6
# Conflicts:
# Zend/Optimizer/zend_inference.c
Changed paths:
A ext/opcache/tests/jit/gh23572.phpt
A ext/opcache/tests/jit/gh23572_001.phpt
A ext/opcache/tests/jit/gh23572_002.phpt
A ext/opcache/tests/jit/gh23572_003.phpt
A ext/opcache/tests/jit/gh23572_004.phpt
M NEWS
M Zend/Optimizer/zend_inference.c
M Zend/Optimizer/zend_optimizer.c
M ext/opcache/jit/zend_jit.c
M ext/opcache/jit/zend_jit_ir.c
Diff:
diff --git a/NEWS b/NEWS
index 1e591d9db522..214cc0a49321 100644
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,9 @@ PHP NEWS
. Fixed function JIT misinterpreting VM-enter results after an interrupt
callback in the CALL and TAILCALL VMs. (Levi Morrison)
. Fixed unsound shift_left_overflows range when shift wraps. (mkrishna793)
+ . Fixed bug GH-23572 (Tracing JIT calls the wrong method for self::/parent::
+ static calls in trait methods shared by several classes). (jorgsowa,
+ mgoulart)
- OpenSSL:
. Fixed bug GH-24784 (openssl_pkcs7_read() and openssl_cms_read() overwrite
diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c
index 851e6fc24adc..25376de43ada 100644
--- a/Zend/Optimizer/zend_inference.c
+++ b/Zend/Optimizer/zend_inference.c
@@ -2464,7 +2464,7 @@ static const zend_property_info *zend_fetch_static_prop_info(const zend_script
*
const zend_property_info *prop_info = NULL;
if (opline->op1_type == IS_CONST) {
const zend_class_entry *ce = NULL;
- if (opline->op2_type == IS_UNUSED) {
+ if (opline->op2_type == IS_UNUSED && !(op_array->fn_flags &
ZEND_ACC_TRAIT_CLONE)) {
uint32_t fetch_type = opline->op2.num & ZEND_FETCH_CLASS_MASK;
switch (fetch_type) {
case ZEND_FETCH_CLASS_SELF:
diff --git a/Zend/Optimizer/zend_optimizer.c b/Zend/Optimizer/zend_optimizer.c
index 4b2e12d9ebf8..93706a8a0d4c 100644
--- a/Zend/Optimizer/zend_optimizer.c
+++ b/Zend/Optimizer/zend_optimizer.c
@@ -846,6 +846,7 @@ zend_class_entry *zend_optimizer_get_class_entry_from_op1(
return zend_optimizer_get_class_entry(script, op_array, Z_STR_P(op1 + 1));
}
} else if (opline->op1_type == IS_UNUSED && op_array->scope
+ && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)
&& !(op_array->scope->ce_flags & ZEND_ACC_TRAIT)
&& ((opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
|| ((opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_STATIC
diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c
index c293e440bb8e..edc6274e578c 100644
--- a/ext/opcache/jit/zend_jit.c
+++ b/ext/opcache/jit/zend_jit.c
@@ -581,6 +581,11 @@ static zend_class_entry* zend_get_known_class(const zend_op_array *op_array,
con
}
} else {
ZEND_ASSERT(op_type == IS_UNUSED);
+ if ((op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)
+ || (op_array->scope && (op_array->scope->ce_flags & ZEND_ACC_TRAIT))) {
+ /* self and parent depend on the class using the trait */
+ return NULL;
+ }
if ((op.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF) {
ce = op_array->scope;
} else {
diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c
index 6df81f4c53a0..146bdc0a5f03 100644
--- a/ext/opcache/jit/zend_jit_ir.c
+++ b/ext/opcache/jit/zend_jit_ir.c
@@ -9323,7 +9323,7 @@ static int zend_jit_init_static_method_call(zend_jit_ctx *jit,
}
ce = zend_get_known_class(op_array, opline, opline->op1_type, opline->op1);
- if (!func && ce && (opline->op1_type == IS_CONST || !(ce->ce_flags &
ZEND_ACC_TRAIT))) {
+ if (!func && ce) {
zval *zv = RT_CONSTANT(opline, opline->op2);
zend_string *method_name;
@@ -16206,7 +16206,7 @@ static int zend_jit_fetch_static_prop(zend_jit_ctx *jit, const zend_op
*opline,
zend_class_entry *ce;
ce = zend_get_known_class(op_array, opline, opline->op2_type, opline->op2);
- if (ce && (opline->op2_type == IS_CONST || !(ce->ce_flags & ZEND_ACC_TRAIT))) {
+ if (ce) {
zval *zv = RT_CONSTANT(opline, opline->op1);
zend_string *prop_name;
diff --git a/ext/opcache/tests/jit/gh23572.phpt b/ext/opcache/tests/jit/gh23572.phpt
new file mode 100644
index 000000000000..018e29cf1133
--- /dev/null
+++ b/ext/opcache/tests/jit/gh23572.phpt
@@ -0,0 +1,85 @@
+--TEST--
+GH-23572: Tracing JIT calls the wrong self/parent static method from trait clones
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=tracing
+opcache.jit_buffer_size=16M
+opcache.jit_hot_func=2
+opcache.jit_hot_loop=255
+opcache.jit_hot_return=255
+opcache.jit_hot_side_exit=255
+--FILE--
+<?php
+class ParentA {
+ public static function method() {
+ return 'parent A';
+ }
+}
+
+class ParentB {
+ public static function method() {
+ return 'parent B';
+ }
+}
+
+trait T {
+ public function callParent() {
+ return parent::method();
+ }
+
+ public function callSelf() {
+ return self::method();
+ }
+}
+
+class A extends ParentA {
+ use T;
+
+ public static function method() {
+ return 'self A';
+ }
+}
+
+class B extends ParentB {
+ use T;
+
+ public static function method() {
+ return 'self B';
+ }
+}
+
+$a = new A;
+$b = new B;
+
+for ($i = 0; $i < 4; $i++) {
+ var_dump($a->callParent());
+}
+var_dump($b->callParent());
+var_dump($b->callParent());
+var_dump($a->callParent());
+
+for ($i = 0; $i < 4; $i++) {
+ var_dump($a->callSelf());
+}
+var_dump($b->callSelf());
+var_dump($b->callSelf());
+var_dump($a->callSelf());
+?>
+--EXPECT--
+string(8) "parent A"
+string(8) "parent A"
+string(8) "parent A"
+string(8) "parent A"
+string(8) "parent B"
+string(8) "parent B"
+string(8) "parent A"
+string(6) "self A"
+string(6) "self A"
+string(6) "self A"
+string(6) "self A"
+string(6) "self B"
+string(6) "self B"
+string(6) "self A"
diff --git a/ext/opcache/tests/jit/gh23572_001.phpt b/ext/opcache/tests/jit/gh23572_001.phpt
new file mode 100644
index 000000000000..d8db1e6341ce
--- /dev/null
+++ b/ext/opcache/tests/jit/gh23572_001.phpt
@@ -0,0 +1,61 @@
+--TEST--
+GH-23572: Tracing JIT calls an instance method statically from trait clones
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=tracing
+opcache.jit_buffer_size=16M
+opcache.jit_hot_func=2
+opcache.jit_max_polymorphic_calls=0
+--FILE--
+<?php
+trait T {
+ public function callSelf() {
+ return self::method();
+ }
+}
+
+class A {
+ use T;
+
+ public static function method() {
+ return 'A';
+ }
+}
+
+class B {
+ use T;
+
+ public function method() {
+ var_dump($this);
+ return 'B';
+ }
+}
+
+$a = new A;
+$b = new B;
+
+for ($i = 0; $i < 4; $i++) var_dump($a->callSelf());
+for ($i = 0; $i < 4; $i++) var_dump($b->callSelf());
+var_dump($a->callSelf());
+?>
+--EXPECTF--
+string(1) "A"
+string(1) "A"
+string(1) "A"
+string(1) "A"
+object(B)#%d (0) {
+}
+string(1) "B"
+object(B)#%d (0) {
+}
+string(1) "B"
+object(B)#%d (0) {
+}
+string(1) "B"
+object(B)#%d (0) {
+}
+string(1) "B"
+string(1) "A"
diff --git a/ext/opcache/tests/jit/gh23572_002.phpt b/ext/opcache/tests/jit/gh23572_002.phpt
new file mode 100644
index 000000000000..15f35e3afa0e
--- /dev/null
+++ b/ext/opcache/tests/jit/gh23572_002.phpt
@@ -0,0 +1,22 @@
+--TEST--
+GH-23572: Function JIT resolves self:: in trait methods to the trait
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit=1205
+opcache.jit_buffer_size=16M
+--FILE--
+<?php
+trait T {
+ public function outer() { return self::inner(); }
+ public function inner() { return static::class; }
+}
+class B { use T; }
+var_dump((new B)->outer(), (new B)->outer());
+?>
+--EXPECT--
+string(1) "B"
+string(1) "B"
diff --git a/ext/opcache/tests/jit/gh23572_003.phpt b/ext/opcache/tests/jit/gh23572_003.phpt
new file mode 100644
index 000000000000..69bdf71779f5
--- /dev/null
+++ b/ext/opcache/tests/jit/gh23572_003.phpt
@@ -0,0 +1,28 @@
+--TEST--
+GH-23572: Function JIT calls a class override of a static trait method via self::
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit=1205
+opcache.jit_buffer_size=16M
+--FILE--
+<?php
+trait T {
+ public function callMethod() { return self::method(); }
+ public static function method() { return 'T'; }
+}
+class A {
+ use T;
+ public function method() {
+ $a = 1; $b = 2; $c = 3; $d = 4; $e = 5; $f = 6; $g = 7; $h = 8;
+ return get_class($this) . ($a + $b + $c + $d + $e + $f + $g + $h);
+ }
+}
+var_dump((new A)->callMethod(), (new A)->callMethod());
+?>
+--EXPECT--
+string(3) "A36"
+string(3) "A36"
diff --git a/ext/opcache/tests/jit/gh23572_004.phpt b/ext/opcache/tests/jit/gh23572_004.phpt
new file mode 100644
index 000000000000..3e73ee4e35bd
--- /dev/null
+++ b/ext/opcache/tests/jit/gh23572_004.phpt
@@ -0,0 +1,26 @@
+--TEST--
+GH-23572: Tracing JIT infers parent:: static property type from the wrong trait clone
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit=tracing
+opcache.jit_buffer_size=16M
+opcache.jit_hot_func=2
+--FILE--
+<?php
+class ParentA { public static int $x = 42; }
+class ParentB { public static string $x = "str"; }
+trait T {
+ public function get() { return parent::$x; }
+}
+class A extends ParentA { use T; }
+class B extends ParentB { use T; }
+var_dump((new A)->get(), (new A)->get(), (new B)->get());
+?>
+--EXPECT--
+int(42)
+int(42)
+string(3) "str"