serialization_objects_004.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST--
  2. Test serialize() & unserialize() functions: objects - ensure that COW references of objects are not serialized separately (unlike other types).
  3. --FILE--
  4. <?php
  5. /* Prototype : proto string serialize(mixed variable)
  6. * Description: Returns a string representation of variable (which can later be unserialized)
  7. * Source code: ext/standard/var.c
  8. * Alias to functions:
  9. */
  10. /* Prototype : proto mixed unserialize(string variable_representation)
  11. * Description: Takes a string representation of variable and recreates it
  12. * Source code: ext/standard/var.c
  13. * Alias to functions:
  14. */
  15. $x = new stdClass;
  16. $ref = &$x;
  17. var_dump(serialize(array($x, $x)));
  18. $x = 1;
  19. $ref = &$x;
  20. var_dump(serialize(array($x, $x)));
  21. $x = "a";
  22. $ref = &$x;
  23. var_dump(serialize(array($x, $x)));
  24. $x = true;
  25. $ref = &$x;
  26. var_dump(serialize(array($x, $x)));
  27. $x = null;
  28. $ref = &$x;
  29. var_dump(serialize(array($x, $x)));
  30. $x = array();
  31. $ref = &$x;
  32. var_dump(serialize(array($x, $x)));
  33. echo "Done";
  34. ?>
  35. --EXPECT--
  36. string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}"
  37. string(22) "a:2:{i:0;i:1;i:1;i:1;}"
  38. string(30) "a:2:{i:0;s:1:"a";i:1;s:1:"a";}"
  39. string(22) "a:2:{i:0;b:1;i:1;b:1;}"
  40. string(18) "a:2:{i:0;N;i:1;N;}"
  41. string(26) "a:2:{i:0;a:0:{}i:1;a:0:{}}"
  42. Done