1--TEST--
2Object Serializable interface
3--SKIPIF--
4<?php
5if (version_compare(PHP_VERSION, '5.1.0') < 0) {
6    echo "skip tests in PHP 5.1 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    echo $type, PHP_EOL;
19    echo bin2hex($serialized), PHP_EOL;
20    var_dump($unserialized);
21    echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
22}
23
24class Obj implements Serializable {
25    var $a;
26    var $b;
27
28    function __construct($a, $b) {
29        $this->a = $a;
30        $this->b = $b;
31    }
32
33    public function serialize() {
34        return pack('NN', $this->a, $this->b);
35    }
36
37    public function unserialize($serialized) {
38        $tmp = unpack('N*', $serialized);
39        $this->__construct($tmp[1], $tmp[2]);
40    }
41}
42
43$o = new Obj(1, 2);
44
45test('object', $o, false);
46?>
47--EXPECTF--
48object
4982c003a34f626aa80000000100000002
50object(Obj)#%d (2) {
51  ["a"]=>
52  int(1)
53  ["b"]=>
54  int(2)
55}
56OK
57