Add a runtime option to raise notices when reading dynamic props.
[hiphop-php.git] / hphp / test / slow / object_property / dynprop_read_notice.php
blob93fdee0cc63c93c8bbd1cce1463c8536ef43d5bd
1 <?hh
3 function test($thing) {
4 echo "==== " . get_class($thing) . " may notice ====\n";
6 echo "== read ==\n";
7 $thing->dynprop = 3;
8 $discard = $thing->dynprop;
10 echo "== read (dynamic name) ==\n";
11 $propname = __hhvm_intrinsics\launder_value("dyn") . "prop";
12 $discard = $thing->$propname;
14 echo "== setOp ==\n";
15 $thing->dynprop += 2;
17 echo "== incDec ==\n";
18 $thing->dynprop++;
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) { }
39 unset($v); // unbind
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";
62 var_dump($thing);
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
83 echo "== vget ==\n";
84 $discard =& $thing->dynprop;
85 unset($discard); // unbind it
87 echo "== bind ==\n";
88 $local = 3;
89 $thing->dynprop =& $local;
90 unset($local); // unbind it
92 echo "== clone ==\n";
93 $discard = clone $thing;
95 echo "== unset ==\n";
96 unset($thing->dynprop);
99 class C {}
100 class D { public $x = 1; }
101 class Extends_stdClass extends stdClass {}
102 class Extends___PHP_Incomplete_Class extends __PHP_Incomplete_Class {}
104 function main() {
105 test(new C());
106 test(new D());
107 test(gmp_init(0));
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());
113 main();