Return to serialize_001.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes |
1.1 ! misho 1: --TEST-- ! 2: ZE2 Serializable ! 3: --FILE-- ! 4: <?php ! 5: ! 6: class Test implements Serializable ! 7: { ! 8: public $data; ! 9: ! 10: function __construct($data) ! 11: { ! 12: echo __METHOD__ . "($data)\n"; ! 13: $this->data = $data; ! 14: } ! 15: ! 16: function serialize() ! 17: { ! 18: echo __METHOD__ . "({$this->data})\n"; ! 19: return $this->data; ! 20: } ! 21: ! 22: function unserialize($serialized) ! 23: { ! 24: echo __METHOD__ . "($serialized)\n"; ! 25: $this->data = $serialized; ! 26: var_dump($this); ! 27: } ! 28: } ! 29: ! 30: $tests = array('String', NULL, 42, false); ! 31: ! 32: foreach($tests as $data) ! 33: { ! 34: try ! 35: { ! 36: echo "==========\n"; ! 37: var_dump($data); ! 38: $ser = serialize(new Test($data)); ! 39: var_dump(unserialize($ser)); ! 40: } ! 41: catch(Exception $e) ! 42: { ! 43: echo 'Exception: ' . $e->getMessage() . "\n"; ! 44: } ! 45: } ! 46: ! 47: ?> ! 48: ===DONE=== ! 49: <?php exit(0); ?> ! 50: --EXPECTF-- ! 51: ========== ! 52: %unicode|string%(6) "String" ! 53: Test::__construct(String) ! 54: Test::serialize(String) ! 55: Test::unserialize(String) ! 56: object(Test)#%d (1) { ! 57: [%u|b%"data"]=> ! 58: %unicode|string%(6) "String" ! 59: } ! 60: object(Test)#%d (1) { ! 61: [%u|b%"data"]=> ! 62: %unicode|string%(6) "String" ! 63: } ! 64: ========== ! 65: NULL ! 66: Test::__construct() ! 67: Test::serialize() ! 68: NULL ! 69: ========== ! 70: int(42) ! 71: Test::__construct(42) ! 72: Test::serialize(42) ! 73: Exception: Test::serialize() must return a string or NULL ! 74: ========== ! 75: bool(false) ! 76: Test::__construct() ! 77: Test::serialize() ! 78: Exception: Test::serialize() must return a string or NULL ! 79: ===DONE===