Skip to content

Commit 574b057

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fixed incorrect type inference
2 parents a0ce529 + 7320f33 commit 574b057

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,9 @@ static zend_always_inline zend_result _zend_update_type_info(
34553455
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
34563456
break;
34573457
case ZEND_FETCH_THIS:
3458-
UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def);
3458+
if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
3459+
UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def);
3460+
}
34593461
UPDATE_SSA_TYPE(MAY_BE_RCN|MAY_BE_OBJECT, ssa_op->result_def);
34603462
break;
34613463
case ZEND_FETCH_OBJ_R:

ext/opcache/tests/jit/gh12482.phpt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
GH-12482: Invalid type inference
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_hot_func=2
7+
--FILE--
8+
<?php
9+
trait T {
10+
function foo() {
11+
$cloned = clone $this;
12+
$cloned->x = 42;
13+
return $cloned;
14+
}
15+
}
16+
class A {
17+
use T;
18+
public $a = 1;
19+
public $b = 2;
20+
public $c = 3;
21+
public $x = 4;
22+
}
23+
class B {
24+
use T;
25+
public $x = 5;
26+
}
27+
$a = new A;
28+
var_dump($a->foo());
29+
var_dump($a->foo());
30+
$b = new B;
31+
var_dump($b->foo());
32+
?>
33+
--EXPECT--
34+
object(A)#2 (4) {
35+
["a"]=>
36+
int(1)
37+
["b"]=>
38+
int(2)
39+
["c"]=>
40+
int(3)
41+
["x"]=>
42+
int(42)
43+
}
44+
object(A)#2 (4) {
45+
["a"]=>
46+
int(1)
47+
["b"]=>
48+
int(2)
49+
["c"]=>
50+
int(3)
51+
["x"]=>
52+
int(42)
53+
}
54+
object(B)#3 (1) {
55+
["x"]=>
56+
int(42)
57+
}

0 commit comments

Comments
 (0)