1--TEST--
2Object test, array of objects with __sleep
3--SKIPIF--
4<?php
5if (version_compare(PHP_VERSION, '5.2.0') < 0) {
6    echo "skip tests in PHP 5.2 or newer";
7}
8--FILE--
9<?php
10if(!extension_loaded('msgpack')) {
11    dl('msgpack.' . PHP_SHLIB_SUFFIX);
12}
13
14function test($type, $variable, $test) {
15    $serialized = msgpack_serialize($variable);
16    $unserialized = msgpack_unserialize($serialized);
17
18    var_dump($variable);
19    var_dump($unserialized);
20}
21
22class Obj {
23    public $a;
24    protected $b;
25    private $c;
26    var $d;
27
28    function __construct($a, $b, $c, $d) {
29        $this->a = $a;
30        $this->b = $b;
31        $this->c = $c;
32        $this->d = $d;
33    }
34
35    function __sleep() {
36        return array('a', 'b', 'c');
37    }
38
39#   function __wakeup() {
40#       $this->d = $this->a + $this->b + $this->c;
41#   }
42}
43
44$array = array(
45    new Obj("aa", "bb", "cc", "dd"),
46    new Obj("ee", "ff", "gg", "hh"),
47    new Obj(1, 2, 3, 4),
48);
49
50
51test('array', $array, true);
52?>
53--EXPECTF--
54array(3) {
55  [0]=>
56  object(Obj)#1 (4) {
57    ["a"]=>
58    string(2) "aa"
59    [%r"?b"?:protected"?%r]=>
60    string(2) "bb"
61    [%r"?c"?:("Obj":)?private"?%r]=>
62    string(2) "cc"
63    ["d"]=>
64    string(2) "dd"
65  }
66  [1]=>
67  object(Obj)#2 (4) {
68    ["a"]=>
69    string(2) "ee"
70    [%r"?b"?:protected"?%r]=>
71    string(2) "ff"
72    [%r"?c"?:("Obj":)?private"?%r]=>
73    string(2) "gg"
74    ["d"]=>
75    string(2) "hh"
76  }
77  [2]=>
78  object(Obj)#3 (4) {
79    ["a"]=>
80    int(1)
81    [%r"?b"?:protected"?%r]=>
82    int(2)
83    [%r"?c"?:("Obj":)?private"?%r]=>
84    int(3)
85    ["d"]=>
86    int(4)
87  }
88}
89array(3) {
90  [0]=>
91  object(Obj)#4 (4) {
92    ["a"]=>
93    string(2) "aa"
94    [%r"?b"?:protected"?%r]=>
95    string(2) "bb"
96    [%r"?c"?:("Obj":)?private"?%r]=>
97    string(2) "cc"
98    ["d"]=>
99    NULL
100  }
101  [1]=>
102  object(Obj)#5 (4) {
103    ["a"]=>
104    string(2) "ee"
105    [%r"?b"?:protected"?%r]=>
106    string(2) "ff"
107    [%r"?c"?:("Obj":)?private"?%r]=>
108    string(2) "gg"
109    ["d"]=>
110    NULL
111  }
112  [2]=>
113  object(Obj)#6 (4) {
114    ["a"]=>
115    int(1)
116    [%r"?b"?:protected"?%r]=>
117    int(2)
118    [%r"?c"?:("Obj":)?private"?%r]=>
119    int(3)
120    ["d"]=>
121    NULL
122  }
123}
124