Merge branch 'PHP-8.1' into PHP-8.2

* PHP-8.1:
  Fixed incorrect type inference
This commit is contained in:
Dmitry Stogov 2023-10-24 18:48:58 +03:00
commit 7320f33f7f
2 changed files with 60 additions and 1 deletions

View File

@ -3451,7 +3451,9 @@ static zend_always_inline zend_result _zend_update_type_info(
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
break;
case ZEND_FETCH_THIS:
UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def);
if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def);
}
UPDATE_SSA_TYPE(MAY_BE_RCN|MAY_BE_OBJECT, ssa_op->result_def);
break;
case ZEND_FETCH_OBJ_R:

View File

@ -0,0 +1,57 @@
--TEST--
GH-12482: Invalid type inference
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit_hot_func=2
--FILE--
<?php
trait T {
function foo() {
$cloned = clone $this;
$cloned->x = 42;
return $cloned;
}
}
class A {
use T;
public $a = 1;
public $b = 2;
public $c = 3;
public $x = 4;
}
class B {
use T;
public $x = 5;
}
$a = new A;
var_dump($a->foo());
var_dump($a->foo());
$b = new B;
var_dump($b->foo());
?>
--EXPECT--
object(A)#2 (4) {
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
["x"]=>
int(42)
}
object(A)#2 (4) {
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
["x"]=>
int(42)
}
object(B)#3 (1) {
["x"]=>
int(42)
}