unserialize.phpt 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. SPL: unserialize with no data (for PHPUnit)
  3. --FILE--
  4. <?php
  5. $types = array('SplDoublyLinkedList', 'SplObjectStorage', 'ArrayObject');
  6. foreach ($types as $type) {
  7. // serialize an empty new object
  8. $exp = serialize(new $type());
  9. // hack to instantiate an object without constructor
  10. $str = sprintf('C:%d:"%s":0:{}', strlen($type), $type);
  11. $obj = unserialize($str);
  12. var_dump($obj);
  13. // serialize result
  14. $out = serialize($obj);
  15. // both should match
  16. var_dump($exp === $out);
  17. }
  18. ?>
  19. --EXPECTF--
  20. object(SplDoublyLinkedList)#%d (2) {
  21. ["flags":"SplDoublyLinkedList":private]=>
  22. int(0)
  23. ["dllist":"SplDoublyLinkedList":private]=>
  24. array(0) {
  25. }
  26. }
  27. bool(true)
  28. object(SplObjectStorage)#%d (1) {
  29. ["storage":"SplObjectStorage":private]=>
  30. array(0) {
  31. }
  32. }
  33. bool(true)
  34. object(ArrayObject)#%d (1) {
  35. ["storage":"ArrayObject":private]=>
  36. array(0) {
  37. }
  38. }
  39. bool(true)