observer_003.phpt 771 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. --TEST--
  2. SPL: SplObjectStorage serialization
  3. --FILE--
  4. <?php
  5. class TestClass
  6. {
  7. public $test = 25;
  8. public function __construct($test = 42)
  9. {
  10. $this->test = $test;
  11. }
  12. }
  13. $storage = new SplObjectStorage();
  14. foreach(array(1,"2","foo",true) as $value)
  15. {
  16. $storage->attach(new TestClass($value));
  17. }
  18. var_dump(count($storage));
  19. foreach($storage as $object)
  20. {
  21. var_dump($object->test);
  22. }
  23. var_dump(serialize($storage));
  24. echo "===UNSERIALIZE===\n";
  25. $storage2 = unserialize(serialize($storage));
  26. var_dump(count($storage2));
  27. foreach($storage2 as $object)
  28. {
  29. var_dump($object->test);
  30. }
  31. ?>
  32. --EXPECTF--
  33. int(4)
  34. int(1)
  35. string(1) "2"
  36. string(3) "foo"
  37. bool(true)
  38. string(%d) "%s"
  39. ===UNSERIALIZE===
  40. int(4)
  41. int(1)
  42. string(1) "2"
  43. string(3) "foo"
  44. bool(true)