1--TEST--
2unserialize() with hooks
3--FILE--
4<?php
5
6class Test {
7    public $prop2 {
8        get { echo __METHOD__, "\n"; }
9    }
10
11    public $prop3 {
12        get { echo __METHOD__, "\n"; }
13        set { echo __METHOD__, "\n"; }
14    }
15
16    public function __construct(
17        public $prop1,
18    ) {}
19}
20
21$test = new Test(1, 2);
22var_dump($s = serialize($test));
23var_dump($test_u = unserialize($s));
24$test_u->prop3;
25$test_u->prop3 = 42;
26
27$s = 'O:4:"Test":1:{s:5:"prop3";i:42;}';
28var_dump(unserialize($s));
29echo "\n";
30
31// Override implicit hook with explicit.
32class Test2 extends Test {
33    public $prop1 {
34        get { echo __METHOD__, "\n"; }
35    }
36}
37
38$test2 = new Test2(1, 2);
39var_dump($s = serialize($test2));
40var_dump($test2_u = unserialize($s));
41$test2_u->prop1;
42$test2_u->prop1 = 42;
43
44$s = 'O:5:"Test2":1:{s:5:"prop1";i:42;}';
45var_dump(unserialize($s));
46
47?>
48--EXPECTF--
49string(31) "O:4:"Test":1:{s:5:"prop1";i:1;}"
50object(Test)#2 (1) {
51  ["prop1"]=>
52  int(1)
53}
54Test::$prop3::get
55Test::$prop3::set
56
57Warning: unserialize(): Cannot unserialize value for virtual property Test::$prop3 in %s on line %d
58
59Warning: unserialize(): Error at offset 26 of 32 bytes in %s on line %d
60bool(false)
61
62string(32) "O:5:"Test2":1:{s:5:"prop1";i:1;}"
63object(Test2)#4 (1) {
64  ["prop1"]=>
65  int(1)
66}
67Test2::$prop1::get
68object(Test2)#5 (1) {
69  ["prop1"]=>
70  int(42)
71}
72