Skip to content

Commit 39bf7ed

Browse files
committed
ext/reflection: fix bug 20873 - cannot assign by reference to overloaded object
1 parent fd7d8bc commit 39bf7ed

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Zend/zend_execute.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,15 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
36243624
ZVAL_ERROR(result);
36253625
goto end;
36263626
}
3627+
if (UNEXPECTED(!Z_REFCOUNTED_P(ptr) && !Z_ISREF_P(ptr) && Z_TYPE_P(ptr) != IS_INDIRECT )) {
3628+
if (Z_TYPE_P(ptr) == IS_FALSE) {
3629+
ZVAL_FALSE(result);
3630+
}
3631+
if (Z_TYPE_P(ptr) == IS_NULL) {
3632+
ZVAL_NULL(result);
3633+
}
3634+
goto end;
3635+
}
36273636
} else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
36283637
ZVAL_ERROR(result);
36293638
goto end;

ext/reflection/tests/bug20873.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Lazy proxy with __get creating references and arithmetic
3+
--FILE--
4+
<?php
5+
class A {
6+
public $_;
7+
8+
public function __get($n) {
9+
global $obj;
10+
11+
// Create a reference to an uninitialized property
12+
$obj->x =& $this->_;
13+
14+
// Static self-reference (edge case)
15+
static $a = $a;
16+
17+
// Arithmetic on reference
18+
$e =& $this->_ - $a;
19+
}
20+
}
21+
22+
$rc = new ReflectionClass(A::class);
23+
$obj = $rc->newLazyProxy(fn() => new A);
24+
$rc->initializeLazyObject($obj);
25+
26+
var_dump($obj->p);
27+
?>
28+
--EXPECTF--
29+
Deprecated: Creation of dynamic property A::$x is deprecated in %s on line %d
30+
31+
Warning: Undefined property: A::$x in %s on line %d
32+
33+
Fatal error: Uncaught Error: Cannot assign by reference to overloaded object in %s:%d
34+
Stack trace:
35+
#0 %s(9): A->__get('x')
36+
#1 %s(23): A->__get('p')
37+
#2 {main}
38+
thrown in %s on line %d
39+
40+

0 commit comments

Comments
 (0)