Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Zend/tests/lazy_objects/gh18038-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var_dump($real->prop);
--EXPECTF--
init
string(19) "RealInstance::__get"
string(12) "Proxy::__get"

Warning: Undefined property: RealInstance::$prop in %s on line %d
NULL
Expand Down
1 change: 0 additions & 1 deletion Zend/tests/lazy_objects/gh18038-007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ var_dump(isset($real->prop['']));
--EXPECT--
init
string(21) "RealInstance::__isset"
string(14) "Proxy::__isset"
bool(false)
bool(false)
32 changes: 32 additions & 0 deletions Zend/tests/lazy_objects/gh21478.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
GH-21478 (Property access on lazy proxy may invoke magic method despite real instance guards)
--FILE--
<?php

class Foo {
public $_;

public function __get($name) {
global $proxy;
printf("__get(\$%s) on %s\n", $name, $this::class);
return $proxy->{$name};
}
}

class Bar extends Foo {}

$rc = new ReflectionClass(Bar::class);
$proxy = $rc->newLazyProxy(function () {
echo "Init\n";
return new Foo();
});

$real = $rc->initializeLazyObject($proxy);
$real->x;

?>
--EXPECTF--
Init
__get($x) on Foo

Warning: Undefined property: Foo::$x in %s on line %d
7 changes: 7 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,13 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int

retval = &EG(uninitialized_zval);

if (UNEXPECTED(zend_object_is_lazy_proxy(zobj)
&& zend_lazy_object_initialized(zobj)
&& (type == BP_VAR_R || type == BP_VAR_IS))) {
zend_object *instance = zend_lazy_object_get_instance(zobj);
return zend_std_read_property(instance, name, type, cache_slot, rv);
}

/* magic isset */
if ((type == BP_VAR_IS) && zobj->ce->__isset) {
zval tmp_result;
Expand Down
Loading