Skip to content
13 changes: 11 additions & 2 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -3624,11 +3624,20 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
ZVAL_ERROR(result);
goto end;
}

if (EXPECTED(Z_TYPE_P(ptr) == IS_NULL)) {
zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);

if (prop_info == NULL) {
ZVAL_NULL(result);
goto end;
}
}
} else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
ZVAL_ERROR(result);
goto end;
}

ZVAL_INDIRECT(result, ptr);
flags &= ZEND_FETCH_OBJ_FLAGS;
if (flags) {
Expand Down Expand Up @@ -5934,4 +5943,4 @@ ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode
break;
}
return ret;
}
}
31 changes: 31 additions & 0 deletions ext/reflection/tests/bug20873.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Lazy proxy with __get creating references and arithmetic
--FILE--
<?php
class A {
public $_;
public function __get($n) {
global $obj;
$obj->x =& $this->_;
static $a = $a;
$e =& $this->_ - $a;
}
}
$rc = new ReflectionClass(A::class);
$obj = $rc->newLazyProxy(fn() => new A);
$rc->initializeLazyObject($obj);
var_dump($obj->p);
?>
--EXPECTF--
Deprecated: Creation of dynamic property A::$x is deprecated in %s on line %d

Warning: Undefined property: A::$x in %s on line %d

Fatal error: Uncaught Error: Cannot assign by reference to overloaded object in %s:%d
Stack trace:
#0 %s(%d): A->__get('x')
#1 %s(%d): A->__get('p')
#2 {main}
thrown in %s on line %d


Loading