1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/lazy_objects/serialize___sleep_initializes.phpt
2025-10-06 10:30:27 +02:00

54 lines
959 B
PHP

--TEST--
Lazy objects: serialize initializes object by default if the __sleep method is used
--FILE--
<?php
class C {
public int $a;
public function __sleep() {
return ['a'];
}
}
function test(string $name, object $obj) {
printf("# %s:\n", $name);
$serialized = serialize($obj);
$unserialized = unserialize($serialized);
var_dump($serialized, $unserialized);
}
$reflector = new ReflectionClass(C::class);
$obj = $reflector->newLazyGhost(function ($obj) {
var_dump("initializer");
$obj->a = 1;
});
test('Ghost', $obj);
$obj = $reflector->newLazyProxy(function ($obj) {
var_dump("initializer");
$c = new C();
$c->a = 1;
return $c;
});
test('Proxy', $obj);
--EXPECTF--
# Ghost:
string(11) "initializer"
string(24) "O:1:"C":1:{s:1:"a";i:1;}"
object(C)#%d (1) {
["a"]=>
int(1)
}
# Proxy:
string(11) "initializer"
string(24) "O:1:"C":1:{s:1:"a";i:1;}"
object(C)#%d (1) {
["a"]=>
int(1)
}