1--TEST-- 2Check behaviour of incomplete class 3--FILE-- 4<?php 5$serialized = 'O:1:"C":1:{s:1:"p";i:1;}'; 6 7$incomplete = unserialize($serialized); 8eval('Class C {}'); 9$complete = unserialize($serialized); 10 11 12echo "\n\n---> Various types of access on complete class:\n" ; 13var_dump($complete); 14var_dump(is_object($complete)); 15var_dump($complete->p); 16 17$ref1 = "ref1.original"; 18$complete->p = &$ref1; 19var_dump($complete->p); 20$ref1 = "ref1.changed"; 21var_dump($complete->p); 22$complete->p = "p.changed"; 23var_dump($ref1); 24 25var_dump(isset($complete->x)); 26$complete->x = "x.new"; 27var_dump(isset($complete->x)); 28unset($complete->x); 29var_dump($complete->x); 30 31 32echo "\n\n---> Same types of access on incomplete class:\n" ; 33var_dump($incomplete); 34var_dump(is_object($incomplete)); 35var_dump($incomplete->p); 36 37try { 38 $ref2 = "ref1.original"; 39 $incomplete->p = &$ref2; 40} catch (Error $e) { 41 echo $e->getMessage(), "\n"; 42} 43var_dump($incomplete->p); 44$ref2 = "ref1.changed"; 45var_dump($incomplete->p); 46try { 47 $incomplete->p = "p.changed"; 48} catch (Error $e) { 49 echo $e->getMessage(), "\n"; 50} 51var_dump($ref1); 52 53var_dump(isset($incomplete->x)); 54try { 55 $incomplete->x = "x.new"; 56} catch (Error $e) { 57 echo $e->getMessage(), "\n"; 58} 59var_dump(isset($incomplete->x)); 60try { 61 unset($incomplete->x); 62} catch (Error $e) { 63 echo $e->getMessage(), "\n"; 64} 65var_dump($incomplete->x); 66 67try { 68 $incomplete->f(); 69} catch (Error $e) { 70 echo $e->getMessage(), "\n"; 71} 72 73echo "Done"; 74?> 75--EXPECTF-- 76---> Various types of access on complete class: 77object(C)#%d (1) { 78 ["p"]=> 79 int(1) 80} 81bool(true) 82int(1) 83string(13) "ref1.original" 84string(12) "ref1.changed" 85string(9) "p.changed" 86bool(false) 87bool(true) 88 89Warning: Undefined property: C::$x in %s on line %d 90NULL 91 92 93---> Same types of access on incomplete class: 94object(__PHP_Incomplete_Class)#%d (2) { 95 ["__PHP_Incomplete_Class_Name"]=> 96 string(1) "C" 97 ["p"]=> 98 int(1) 99} 100bool(true) 101 102Warning: main(): The script tried to access a property on 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 an autoloader to load the class definition in %s on line %d 103NULL 104The script tried to modify a property on 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 an autoloader to load the class definition 105 106Warning: main(): The script tried to access a property on 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 an autoloader to load the class definition in %s on line %d 107NULL 108 109Warning: main(): The script tried to access a property on 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 an autoloader to load the class definition in %s on line %d 110NULL 111The script tried to modify a property on 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 an autoloader to load the class definition 112string(9) "p.changed" 113 114Warning: main(): The script tried to access a property on 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 an autoloader to load the class definition in %s on line %d 115bool(false) 116The script tried to modify a property on 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 an autoloader to load the class definition 117 118Warning: main(): The script tried to access a property on 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 an autoloader to load the class definition in %s on line %d 119bool(false) 120The script tried to modify a property on 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 an autoloader to load the class definition 121 122Warning: main(): The script tried to access a property on 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 an autoloader to load the class definition in %s on line %d 123NULL 124The script tried to call a method on 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 an autoloader to load the class definition 125Done 126