mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Fix nullsafe operator on reference
Dereference the value before checking the type. As the happy path necessarily has to check for references, I'm not bothering to delay the comparison.
This commit is contained in:
parent
75baa729f5
commit
f491dabe40
18
Zend/tests/nullsafe_operator/031.phpt
Normal file
18
Zend/tests/nullsafe_operator/031.phpt
Normal file
@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
Nullsafe operator on referenced value
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$val = null;
|
||||
$ref =& $val;
|
||||
var_dump($ref?->foo);
|
||||
|
||||
$val = new stdClass;
|
||||
var_dump($ref?->foo);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
NULL
|
||||
|
||||
Warning: Undefined property: stdClass::$foo in %s on line %d
|
||||
NULL
|
@ -7325,6 +7325,9 @@ ZEND_VM_HOT_NOCONST_HANDLER(198, ZEND_JMP_NULL, CONST|TMPVARCV, JMP_ADDR)
|
||||
zval *val;
|
||||
|
||||
val = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
|
||||
if (OP1_TYPE != IS_CONST) {
|
||||
ZVAL_DEREF(val);
|
||||
}
|
||||
|
||||
if (Z_TYPE_INFO_P(val) > IS_NULL) {
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
|
@ -4375,6 +4375,9 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_NULL_SPEC_CON
|
||||
zval *val;
|
||||
|
||||
val = RT_CONSTANT(opline, opline->op1);
|
||||
if (IS_CONST != IS_CONST) {
|
||||
ZVAL_DEREF(val);
|
||||
}
|
||||
|
||||
if (Z_TYPE_INFO_P(val) > IS_NULL) {
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
@ -11095,6 +11098,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_NULL_SPEC_TMPV
|
||||
zval *val;
|
||||
|
||||
val = EX_VAR(opline->op1.var);
|
||||
if ((IS_TMP_VAR|IS_VAR|IS_CV) != IS_CONST) {
|
||||
ZVAL_DEREF(val);
|
||||
}
|
||||
|
||||
if (Z_TYPE_INFO_P(val) > IS_NULL) {
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
|
Loading…
Reference in New Issue
Block a user