diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 518cbb98fc0f8..5409df3b44a76 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -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) { @@ -5934,4 +5943,4 @@ ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode break; } return ret; -} +} \ No newline at end of file diff --git a/ext/reflection/tests/bug20873.phpt b/ext/reflection/tests/bug20873.phpt new file mode 100644 index 0000000000000..025abaee3608a --- /dev/null +++ b/ext/reflection/tests/bug20873.phpt @@ -0,0 +1,31 @@ +--TEST-- +Lazy proxy with __get creating references and arithmetic +--FILE-- +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 + +