Skip to content

Commit 1040f30

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Check for undef var in typed property assignment
2 parents b963575 + 4c31edb commit 1040f30

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,13 @@ static void ZEND_FASTCALL zend_jit_assign_to_typed_prop(zval *property_val, zend
20682068
zend_execute_data *execute_data = EG(current_execute_data);
20692069
zval tmp;
20702070

2071+
if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
2072+
const zend_op *op_data = execute_data->opline + 1;
2073+
ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
2074+
zend_jit_undefined_op_helper(op_data->op1.var);
2075+
value = &EG(uninitialized_zval);
2076+
}
2077+
20712078
if (UNEXPECTED(info->flags & ZEND_ACC_READONLY)) {
20722079
zend_readonly_property_modification_error(info);
20732080
if (result) {

ext/opcache/tests/jit/assign_obj_002.phpt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,27 @@ opcache.jit=function
1010
<?php
1111
class Test {
1212
public $prop;
13+
public int $prop2;
1314
}
1415
function test() {
1516
$o = new Test;
1617
$o->prop = $undef;
1718
var_dump($o->prop);
1819
}
20+
function test2() {
21+
$o = new Test;
22+
$o->prop2 = $undef;
23+
}
1924
test();
25+
try {
26+
test2();
27+
} catch (TypeError $e) {
28+
echo $e->getMessage(), "\n";
29+
}
2030
?>
21-
DONE
2231
--EXPECTF--
23-
Warning: Undefined variable $undef in %sassign_obj_002.php on line 7
32+
Warning: Undefined variable $undef in %s on line %d
2433
NULL
25-
DONE
34+
35+
Warning: Undefined variable $undef in %s on line %d
36+
Cannot assign null to property Test::$prop2 of type int

0 commit comments

Comments
 (0)