Skip to content

Commit

Permalink
Check for undef var in typed property assignment
Browse files Browse the repository at this point in the history
Without this check the assignment would actually silently succeed,
not just skip the warning.
  • Loading branch information
nikic committed Sep 21, 2021
1 parent 48d050e commit f4bcf8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ext/opcache/jit/zend_jit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,13 @@ static void ZEND_FASTCALL zend_jit_assign_to_typed_prop(zval *property_val, zend
zend_execute_data *execute_data = EG(current_execute_data);
zval tmp;

if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
const zend_op *op_data = execute_data->opline + 1;
ZEND_ASSERT(op_data->opcode == ZEND_OP_DATA && op_data->op1_type == IS_CV);
zend_jit_undefined_op_helper(op_data->op1.var);
value = &EG(uninitialized_zval);
}

ZVAL_DEREF(value);
ZVAL_COPY(&tmp, value);

Expand Down
17 changes: 14 additions & 3 deletions ext/opcache/tests/jit/assign_obj_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@ opcache.jit=function
<?php
class Test {
public $prop;
public int $prop2;
}
function test() {
$o = new Test;
$o->prop = $undef;
var_dump($o->prop);
}
function test2() {
$o = new Test;
$o->prop2 = $undef;
}
test();
try {
test2();
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
DONE
--EXPECTF--
Warning: Undefined variable $undef in %sassign_obj_002.php on line 7
Warning: Undefined variable $undef in %s on line %d
NULL
DONE

Warning: Undefined variable $undef in %s on line %d
Cannot assign null to property Test::$prop2 of type int

0 comments on commit f4bcf8c

Please sign in to comment.