1--TEST-- 2Test var_export() function with valid objects 3--FILE-- 4<?php 5/* Prototype : mixed var_export(mixed var [, bool return]) 6 * Description: Outputs or returns a string representation of a variable 7 * Source code: ext/standard/var.c 8 * Alias to functions: 9 */ 10 11echo "*** Testing var_export() with valid objects ***\n"; 12 13// class with no members 14class foo 15{ 16// no members 17} 18 19// abstract class 20abstract class abstractClass 21{ 22 abstract protected function getClassName(); 23 public function printClassName () { 24 echo $this->getClassName() . "\n"; 25 } 26} 27// implement abstract class 28class concreteClass extends abstractClass 29{ 30 protected function getClassName() { 31 return "concreteClass"; 32 } 33} 34 35// interface class 36interface iValue 37{ 38 public function setVal ($name, $val); 39 public function dumpVal (); 40} 41// implement the interface 42class Value implements iValue 43{ 44 private $vars = array (); 45 46 public function setVal ( $name, $val ) { 47 $this->vars[$name] = $val; 48 } 49 50 public function dumpVal () { 51 var_export ( $vars ); 52 } 53} 54 55// a gereral class 56class myClass 57{ 58 var $foo_object; 59 public $public_var; 60 public $public_var1; 61 private $private_var; 62 protected $protected_var; 63 64 function myClass ( ) { 65 $this->foo_object = new foo(); 66 $this->public_var = 10; 67 $this->public_var1 = new foo(); 68 $this->private_var = new foo(); 69 $this->proected_var = new foo(); 70 } 71} 72 73// create a object of each class defined above 74$myClass_object = new myClass(); 75$foo_object = new foo(); 76$Value_object = new Value(); 77$concreteClass_object = new concreteClass(); 78 79$valid_objects = array( 80 "new stdclass" => new stdclass, 81 "new foo" => new foo, 82 "new concreteClass" => new concreteClass, 83 "new Value" => new Value, 84 "new myClass" => new myClass, 85 "myClass_object" => $myClass_object, 86 "myClass_object->foo_object" => $myClass_object->foo_object, 87 "myClass_object->public_var1" => $myClass_object->public_var1, 88 "foo_object" => $foo_object, 89 "Value_object" => $Value_object, 90 "concreteClass_object" => $concreteClass_object 91 ); 92/* Loop to check for above objects with var_export() */ 93echo "\n*** Output for objects ***\n"; 94foreach($valid_objects as $key => $obj) { 95 echo "\n-- Iteration: $key --\n"; 96 var_export( $obj ); 97 echo "\n"; 98 var_export( $obj, FALSE); 99 echo "\n"; 100 var_dump( var_export( $obj, TRUE) ); 101 echo "\n"; 102} 103?> 104===DONE=== 105--EXPECT-- 106*** Testing var_export() with valid objects *** 107 108*** Output for objects *** 109 110-- Iteration: new stdclass -- 111stdClass::__set_state(array( 112)) 113stdClass::__set_state(array( 114)) 115string(31) "stdClass::__set_state(array( 116))" 117 118 119-- Iteration: new foo -- 120foo::__set_state(array( 121)) 122foo::__set_state(array( 123)) 124string(26) "foo::__set_state(array( 125))" 126 127 128-- Iteration: new concreteClass -- 129concreteClass::__set_state(array( 130)) 131concreteClass::__set_state(array( 132)) 133string(36) "concreteClass::__set_state(array( 134))" 135 136 137-- Iteration: new Value -- 138Value::__set_state(array( 139 'vars' => 140 array ( 141 ), 142)) 143Value::__set_state(array( 144 'vars' => 145 array ( 146 ), 147)) 148string(57) "Value::__set_state(array( 149 'vars' => 150 array ( 151 ), 152))" 153 154 155-- Iteration: new myClass -- 156myClass::__set_state(array( 157 'foo_object' => 158 foo::__set_state(array( 159 )), 160 'public_var' => 10, 161 'public_var1' => 162 foo::__set_state(array( 163 )), 164 'private_var' => 165 foo::__set_state(array( 166 )), 167 'protected_var' => NULL, 168 'proected_var' => 169 foo::__set_state(array( 170 )), 171)) 172myClass::__set_state(array( 173 'foo_object' => 174 foo::__set_state(array( 175 )), 176 'public_var' => 10, 177 'public_var1' => 178 foo::__set_state(array( 179 )), 180 'private_var' => 181 foo::__set_state(array( 182 )), 183 'protected_var' => NULL, 184 'proected_var' => 185 foo::__set_state(array( 186 )), 187)) 188string(293) "myClass::__set_state(array( 189 'foo_object' => 190 foo::__set_state(array( 191 )), 192 'public_var' => 10, 193 'public_var1' => 194 foo::__set_state(array( 195 )), 196 'private_var' => 197 foo::__set_state(array( 198 )), 199 'protected_var' => NULL, 200 'proected_var' => 201 foo::__set_state(array( 202 )), 203))" 204 205 206-- Iteration: myClass_object -- 207myClass::__set_state(array( 208 'foo_object' => 209 foo::__set_state(array( 210 )), 211 'public_var' => 10, 212 'public_var1' => 213 foo::__set_state(array( 214 )), 215 'private_var' => 216 foo::__set_state(array( 217 )), 218 'protected_var' => NULL, 219 'proected_var' => 220 foo::__set_state(array( 221 )), 222)) 223myClass::__set_state(array( 224 'foo_object' => 225 foo::__set_state(array( 226 )), 227 'public_var' => 10, 228 'public_var1' => 229 foo::__set_state(array( 230 )), 231 'private_var' => 232 foo::__set_state(array( 233 )), 234 'protected_var' => NULL, 235 'proected_var' => 236 foo::__set_state(array( 237 )), 238)) 239string(293) "myClass::__set_state(array( 240 'foo_object' => 241 foo::__set_state(array( 242 )), 243 'public_var' => 10, 244 'public_var1' => 245 foo::__set_state(array( 246 )), 247 'private_var' => 248 foo::__set_state(array( 249 )), 250 'protected_var' => NULL, 251 'proected_var' => 252 foo::__set_state(array( 253 )), 254))" 255 256 257-- Iteration: myClass_object->foo_object -- 258foo::__set_state(array( 259)) 260foo::__set_state(array( 261)) 262string(26) "foo::__set_state(array( 263))" 264 265 266-- Iteration: myClass_object->public_var1 -- 267foo::__set_state(array( 268)) 269foo::__set_state(array( 270)) 271string(26) "foo::__set_state(array( 272))" 273 274 275-- Iteration: foo_object -- 276foo::__set_state(array( 277)) 278foo::__set_state(array( 279)) 280string(26) "foo::__set_state(array( 281))" 282 283 284-- Iteration: Value_object -- 285Value::__set_state(array( 286 'vars' => 287 array ( 288 ), 289)) 290Value::__set_state(array( 291 'vars' => 292 array ( 293 ), 294)) 295string(57) "Value::__set_state(array( 296 'vars' => 297 array ( 298 ), 299))" 300 301 302-- Iteration: concreteClass_object -- 303concreteClass::__set_state(array( 304)) 305concreteClass::__set_state(array( 306)) 307string(36) "concreteClass::__set_state(array( 308))" 309 310===DONE=== 311