1--TEST-- 2Object test, __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 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 { 25 public $a; 26 protected $b; 27 private $c; 28 var $d; 29 30 function __construct($a, $b, $c, $d) { 31 $this->a = $a; 32 $this->b = $b; 33 $this->c = $c; 34 $this->d = $d; 35 } 36 37 function __sleep() { 38 return array('a', 'b', 'c'); 39 } 40 41# function __wakeup() { 42# $this->d = $this->a + $this->b + $this->c; 43# } 44} 45 46$o = new Obj(1, 2, 3, 4); 47 48 49test('object', $o, true); 50?> 51--EXPECTF-- 52object 5384c0a34f626aa16101a4002a006202a6004f626a006303 54object(Obj)#%d (4) { 55 ["a"]=> 56 int(1) 57 [%r"?b"?:protected"?%r]=> 58 int(2) 59 [%r"?c"?:("Obj":)?private"?%r]=> 60 int(3) 61 ["d"]=> 62 NULL 63} 64OK 65