3 function test($thing) {
4 echo "==== " . get_class($thing) . " may notice ====\n";
8 $discard = $thing->dynprop
;
10 echo "== read (dynamic name) ==\n";
11 $propname = __hhvm_intrinsics\
launder_value("dyn") . "prop";
12 $discard = $thing->$propname;
17 echo "== incDec ==\n";
20 echo "== dim for read ==\n";
21 $thing->dynprop
= array('a' => 'b');
22 $discard = $thing->dynprop
['a'];
24 echo "== dim for read (quiet) ==\n";
25 $discard = $thing->dynprop
['z'] ??
'w';
26 $thing->dynprop
= 3; // set prop back to an int
28 echo "== cast to array ==\n";
29 $discard = (array)$thing;
31 echo "== get_object_vars ==\n";
32 $discard = get_object_vars($thing);
34 echo "== foreach ==\n";
35 foreach ($thing as $k => $v) { }
37 echo "== foreach by reference ==\n";
38 foreach ($thing as $k => &$v) { }
41 echo "== ReflectionProperty ==\n";
42 $discard = new ReflectionProperty($thing, 'dynprop');
44 // TODO: ReflectionClass constructor fatals on instances of
45 // __PHP_Incomplete_Class
46 if (!$thing instanceof __PHP_Incomplete_Class
) {
47 echo "== ReflectionClass::getProperties ==\n";
48 $rc = new ReflectionClass($thing);
49 $discard = $rc->getProperties();
52 echo "== property_exists ==\n";
53 $discard = property_exists($thing, 'dynprop');
55 echo "== print_r ==\n";
56 $discard = print_r($thing, true);
58 echo "== var_export ==\n";
59 $discard = var_export($thing, true);
61 echo "== var_dump ==\n";
64 echo "== debug_zval_dump ==\n";
65 debug_zval_dump($thing);
67 echo "== json_encode ==\n";
68 $discard = json_encode($thing);
70 echo "== serialize ==\n";
71 $discard = serialize($thing);
73 echo "== apc_store ==\n";
74 apc_store('dynamic', $thing);
76 echo "==== " . get_class($thing) . " never notice ====\n";
78 echo "== dim for write ==\n";
79 $thing->dynprop
= array('a' => 'b');
80 $thing->dynprop
['c'] = 'd';
81 $thing->dynprop
= 3; // set prop back to an int
84 $discard =& $thing->dynprop
;
85 unset($discard); // unbind it
89 $thing->dynprop
=& $local;
90 unset($local); // unbind it
93 $discard = clone $thing;
96 unset($thing->dynprop
);
100 class D
{ public $x = 1; }
101 class Extends_stdClass
extends stdClass
{}
102 class Extends___PHP_Incomplete_Class
extends __PHP_Incomplete_Class
{}
108 test(new stdClass());
109 test(unserialize('O:4:"Nope":0:{}')); // __PHP_Incomplete_Class
110 test(new Extends_stdClass());
111 test(new Extends___PHP_Incomplete_Class());