1--TEST--
2Object test, __sleep and __wakeup exceptions
3--SKIPIF--
4--FILE--
5<?php
6if(!extension_loaded('msgpack')) {
7    dl('msgpack.' . PHP_SHLIB_SUFFIX);
8}
9
10error_reporting(0);
11
12function test($variable) {
13    $serialized = msgpack_serialize($variable);
14    $unserialized = msgpack_unserialize($serialized);
15    var_dump($unserialized);
16}
17
18class Obj {
19    private static $count = 0;
20    var $a;
21    var $b;
22
23    function __construct($a, $b) {
24        $this->a = $a;
25        $this->b = $b;
26    }
27
28    function __sleep() {
29        $c = self::$count++;
30        if ($this->a) {
31            throw new Exception("exception in __sleep $c");
32        }
33        return array('a', 'b');
34    }
35
36    function __wakeup() {
37        $c = self::$count++;
38        if ($this->b) {
39            throw new Exception("exception in __wakeup $c");
40        }
41        $this->b = $this->a * 3;
42    }
43}
44
45
46$a = new Obj(1, 0);
47$b = new Obj(0, 1);
48$c = new Obj(0, 0);
49
50try {
51    test($a);
52} catch (Exception $e) {
53    echo $e->getMessage(), PHP_EOL;
54}
55
56try {
57    test($b);
58} catch (Exception $e) {
59    echo $e->getMessage(), PHP_EOL;
60}
61
62try {
63    test($c);
64} catch (Exception $e) {
65    echo $e->getMessage(), PHP_EOL;
66}
67?>
68--EXPECTF--
69exception in __sleep 0
70exception in __wakeup 2
71object(Obj)#%d (2) {
72  ["a"]=>
73  int(0)
74  ["b"]=>
75  int(0)
76}
77