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.
--- /dev/null
+--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
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();
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();
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();