Skip to content

Commit f4bcf8c

Browse files
committed
Check for undef var in typed property assignment
Without this check the assignment would actually silently succeed, not just skip the warning.
1 parent 48d050e commit f4bcf8c

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
@@ -2162,6 +2162,13 @@ static void ZEND_FASTCALL zend_jit_assign_to_typed_prop(zval *property_val, zend
21622162
zend_execute_data *execute_data = EG(current_execute_data);
21632163
zval tmp;
21642164

2165+
if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
2166+
const zend_op *op_data = execute_data->opline + 1;
2167+
ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
2168+
zend_jit_undefined_op_helper(op_data->op1.var);
2169+
value = &EG(uninitialized_zval);
2170+
}
2171+
21652172
ZVAL_DEREF(value);
21662173
ZVAL_COPY(&tmp, value);
21672174

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)