serialization_objects_003.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. Test serialize() & unserialize() functions: objects (abstract classes)
  3. --INI--
  4. serialize_precision=100
  5. --FILE--
  6. <?php
  7. /* Prototype : proto string serialize(mixed variable)
  8. * Description: Returns a string representation of variable (which can later be unserialized)
  9. * Source code: ext/standard/var.c
  10. * Alias to functions:
  11. */
  12. /* Prototype : proto mixed unserialize(string variable_representation)
  13. * Description: Takes a string representation of variable and recreates it
  14. * Source code: ext/standard/var.c
  15. * Alias to functions:
  16. */
  17. echo "\n--- Testing Abstract Class ---\n";
  18. // abstract class
  19. abstract class Name
  20. {
  21. public function __construct() {
  22. $this->a = 10;
  23. $this->b = 12.222;
  24. $this->c = "string";
  25. }
  26. abstract protected function getClassName();
  27. public function printClassName () {
  28. return $this->getClassName();
  29. }
  30. }
  31. // implement abstract class
  32. class extendName extends Name
  33. {
  34. var $a, $b, $c;
  35. protected function getClassName() {
  36. return "extendName";
  37. }
  38. }
  39. $obj_extendName = new extendName();
  40. $serialize_data = serialize($obj_extendName);
  41. var_dump( $serialize_data );
  42. $unserialize_data = unserialize($serialize_data);
  43. var_dump( $unserialize_data );
  44. $serialize_data = serialize($obj_extendName->printClassName());
  45. var_dump( $serialize_data );
  46. $unserialize_data = unserialize($serialize_data);
  47. var_dump( $unserialize_data );
  48. echo "\nDone";
  49. ?>
  50. --EXPECTF--
  51. --- Testing Abstract Class ---
  52. string(119) "O:10:"extendName":3:{s:1:"a";i:10;s:1:"b";d:12.2219999999999995310417943983338773250579833984375;s:1:"c";s:6:"string";}"
  53. object(extendName)#%d (3) {
  54. ["a"]=>
  55. int(10)
  56. ["b"]=>
  57. float(12.222)
  58. ["c"]=>
  59. string(6) "string"
  60. }
  61. string(18) "s:10:"extendName";"
  62. string(10) "extendName"
  63. Done