serialization_objects_005.phpt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. --TEST--
  2. Check behaviour of incomplete class
  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. $serialized = 'O:1:"C":1:{s:1:"p";i:1;}';
  16. $incomplete = unserialize($serialized);
  17. eval('Class C {}');
  18. $complete = unserialize($serialized);
  19. echo "\n\n---> Various types of access on complete class:\n" ;
  20. var_dump($complete);
  21. var_dump(is_object($complete));
  22. var_dump($complete->p);
  23. $ref1 = "ref1.original";
  24. $complete->p = &$ref1;
  25. var_dump($complete->p);
  26. $ref1 = "ref1.changed";
  27. var_dump($complete->p);
  28. $complete->p = "p.changed";
  29. var_dump($ref1);
  30. var_dump(isset($complete->x));
  31. $complete->x = "x.new";
  32. var_dump(isset($complete->x));
  33. unset($complete->x);
  34. var_dump($complete->x);
  35. echo "\n\n---> Same types of access on incomplete class:\n" ;
  36. var_dump($incomplete);
  37. var_dump(is_object($incomplete));
  38. var_dump($incomplete->p);
  39. $ref2 = "ref1.original";
  40. $incomplete->p = &$ref2;
  41. var_dump($incomplete->p);
  42. $ref2 = "ref1.changed";
  43. var_dump($incomplete->p);
  44. $incomplete->p = "p.changed";
  45. var_dump($ref1);
  46. var_dump(isset($incomplete->x));
  47. $incomplete->x = "x.new";
  48. var_dump(isset($incomplete->x));
  49. unset($incomplete->x);
  50. var_dump($incomplete->x);
  51. $incomplete->f();
  52. echo "Done";
  53. ?>
  54. --EXPECTF--
  55. ---> Various types of access on complete class:
  56. object(C)#%d (1) {
  57. ["p"]=>
  58. int(1)
  59. }
  60. bool(true)
  61. int(1)
  62. string(13) "ref1.original"
  63. string(12) "ref1.changed"
  64. string(9) "p.changed"
  65. bool(false)
  66. bool(true)
  67. Notice: Undefined property: C::$x in %s on line 37
  68. NULL
  69. ---> Same types of access on incomplete class:
  70. object(__PHP_Incomplete_Class)#%d (2) {
  71. ["__PHP_Incomplete_Class_Name"]=>
  72. string(1) "C"
  73. ["p"]=>
  74. int(1)
  75. }
  76. bool(false)
  77. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 43
  78. NULL
  79. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 46
  80. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 47
  81. NULL
  82. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 49
  83. NULL
  84. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 50
  85. string(9) "p.changed"
  86. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 53
  87. bool(false)
  88. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 54
  89. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 55
  90. bool(false)
  91. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 56
  92. Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 57
  93. NULL
  94. Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 59