Turn on Eval.EnableObjDestructCall by default
[hiphop-php.git] / hphp / doc / inconsistencies
bloba056b947c4ba6bb89ad9afa1be38170052c9fa34
1 <h2>Inconsistencies between PHP5 and HipHop VM</h2>
4 1. Arrays and foreach loops
6 (1) Next free integer key for arrays
8 Arrays contain a hidden field called the "NextFreeElement" field that tracks
9 what integer key should be used when a new element is appended. Under PHP5,
10 when an array is copied the NextFreeElement field of the new array will be
11 recomputed based on the keys it currently contains. Under HipHop VM, when an
12 array is copied the new array's NextFreeElement field is set to the same value
13 as the original array's NextFreeElement field.
15 (2) Array internal cursors
17 Under PHP5, if an array's internal cursor points to the position past the
18 last element and then a copy of the array is made, the copy will have its
19 internal cursor reset to point at the first element. Under HipHop VM, when a
20 copy of an array is made, the copy's internal cursor will always point to the
21 same position that the original array's internal cursor pointed to.
23 (3) Foreach by value
25 Under PHP5, foreach by value will modify the array's internal cursor under
26 certain circumstances. Under HipHop VM, foreach by value will never modify the
27 array's internal cursor.
29 (4) Foreach by reference
31 Under PHP5, the behavior of a foreach by reference loop can be
32 unpredictable if during iteration the next element of the array is unset, or if
33 the array variable is assigned to directly or through a reference, or if
34 copy-on-write causes the array to be copied. For such cases, HipHop VM's
35 behavior may differ from PHP5.
38 2. Classes and objects
40 (1) Exceptions thrown from destructors
42 Under HipHop VM, PHP exceptions thrown from destructors will be
43 swallowed while logging an error. Effectively, there is a try/catch enclosing
44 the body of the __destruct method. These exceptions are catchable under Zend
45 PHP outside of the __destruct method.
47 Fatals thrown from destructors will log an error, and prevent further PHP code
48 from executing as the fatal propagates. This includes other __destruct methods.
50 (2) Exceptions thrown from __toString()
52 PHP5 does not allow exceptions to be thrown from __toString(). HipHop VM
53 does. Also, PHP5 doesn't allow __toString() to return anything other than a
54 string. HipHop VM will just convert return value to string.
56 (3) __call/__callStatic() handling
58 This example gives inconsistent results in PHP 5.5:
60   <?php
61   class B {
62   }
63   class G extends B {
64     function __call($name, $arguments) { var_dump('G');}
65     function f4missing($a) {
66       B::f4missing(5); // __call checking happened at B
67     }
68   }
69   $g = new G();
70   $g->f4missing(3);
72 Under HipHop VM, both checking and invocation of __call() happen on class G.
74 (4) Object internal cursors
76 Under PHP5, objects have an internal cursor (similar to the array internal
77 cursor) that can be used to iterate over the object's properties. Under HipHop
78 VM, objects do not have internal cursors, and the next(), prev(), current(),
79 key(), reset(), end(), and each() builtin functions do not support objects.
81 (5) Supressing errors for params to default constructors
83 If a class doesn't define a constructor then you construct that object passing
84 whatever you want, including things that would fatal the runtime. HHVM doesn't
85 allow this, and will always evaluate the args whether the class has a
86 constructor or not.
88   <?php
89   class A {}
90   var_dump(new A(undefined_function())); // Works in PHP5 but not HHVM
92   class B {
93     public function __construct() {
94     }
95   }
96   var_dump(new B(undefined_function())); // Doesn't work in neither HHVM nor PHP5
99 3. Misc
101 (1) Case-insensitive constants
103 HipHop VM does not support case-insensitive constants, for example:
104   define('FOO', 123, true);
106 (2) get_defined_vars() and get_declared_classes()
108 HipHop VM may return variables/classes in a different order than PHP5.
110 (3) XMLWriter
112 Under PHP5, XMLWriter class and its functions returned different types of
113 objects,
115   <?php
116   function foo(XMLWriter $w) {}
117   $obj = new XMLWriter();
118   foo($obj); // <-- this one is actually okay
119   $obj2 = xmlwriter_open_memory(); // <-- just not this one
120   var_dump($obj, $obj2);
121   foo($obj2);
123 Under HipHop VM, they are the same.
125 (4) HipHop VM only supports preg_replace /e in limited cases.
126 Example unsupported case: phpt...bug24403
128 (5) Under PHP5, you can assign to $GLOBALS:
130   $GLOBALS = 0;
131   $x = $GLOBALS - 5;
133   $g = $GLOBALS;
134   $g['x'] = 3;
136 Under HipHop VM, this is not allowed or not working at present.
138 (6) Converting $GLOBALS to bool will always evaluate to true, even if $GLOBALS
139 is empty. Converting to bool can mean an explicit cast, or an implicit
140 conversion inside the condition of an if statement or similar.
142 (7) All fatals prevent further PHP code from executing, including __destruct
143 methods. N.B.: exit() is a fatal.
145 (8) Loading of external entities in the libxml extension is disabled by default
146 for security reasons. It can be re-enabled on a per-protocol basis (file, http,
147 compress.zlib, etc...) with a comma-separated list in the ini setting
148 hhvm.libxml.ext_entity_whitelist.