Skip to content

Commit

Permalink
Fix FETCH_OBJ_IS type inference
Browse files Browse the repository at this point in the history
Even if the property is typed, null is still a valid return
value in the BP_VAR_IS case. Other cases will throw instead.
  • Loading branch information
nikic committed Sep 17, 2021
1 parent 015cafa commit a49a309
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -3452,6 +3452,10 @@ static zend_always_inline int _zend_update_type_info(
tmp &= ~MAY_BE_RC1;
}
}
if (opline->opcode == ZEND_FETCH_OBJ_IS) {
/* IS check may return null for uninitialized typed property. */
tmp |= MAY_BE_NULL;
}
}
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
if (ce) {
Expand Down
24 changes: 24 additions & 0 deletions ext/opcache/tests/jit/fetch_obj_is_typed_prop.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
FETCH_OBJ_IS on typed object property
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php

class Test {
public stdClass $data;
}

function test() {
$test = new Test;
var_dump(isset($test->data[0]));
}

test();

?>
--EXPECT--
bool(false)

0 comments on commit a49a309

Please sign in to comment.