php-src/Zend/tests/lazy_objects/serialize___sleep.phpt
Arnaud Le Blanc c65e042c0b
Fix zend_get_property_info_for_slot() for lazy objects (#15855)
zend_get_property_info_for_slot(obj, slot) assumes that 'slot' belongs to 'obj', but that may not be the case for lazy proxies.

Fortunately, the property info is often already available in path when it is needed.

For other cases, I make zend_get_property_info_for_slot() aware of lazy objects, and add zend_get_property_info_for_slot_self() for cases where the 'slot' is known to belong to the object itself.

Fixes oss-fuzz #71446
2024-09-16 16:58:12 +02:00

42 lines
876 B
PHP

--TEST--
Lazy Objects: serialize with __sleep fetches property info from the real instance
--FILE--
<?php
class C {
public mixed $a;
private mixed $b = 1;
function __sleep() {
return['a', 'b'];
}
}
$reflector = new ReflectionClass(C::class);
print "Init on serialize and successful initialization\n";
$obj = $reflector->newLazyProxy(function() {
$c = new C;
return $c;
});
var_dump(serialize($obj));
print "Init on serialize and failed initialization\n";
$obj = $reflector->newLazyProxy(function() {
throw new \Exception('initializer');
});
try {
var_dump(serialize($obj));
} catch (Exception $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
?>
--EXPECTF--
Init on serialize and successful initialization
string(27) "O:1:"C":1:{s:4:"%0C%0b";i:1;}"
Init on serialize and failed initialization
Exception: initializer