1 <h2>Inconsistencies between Zend PHP and HipHop VM</h2>
4 1. Arithmetic, arrays, and foreach loops
8 Under Zend PHP, the addition, subtraction, or multiplication of two integers
9 will produce a floating-point value if the result overflows the integer type.
10 Under HipHop VM, the addition, subtraction, or multiplication of two integers
11 will always produce an integer value; if the result overflows the integer type,
12 the high bits of the result will be discarded ("wrap-around").
14 (2) Next free integer key for arrays
16 Arrays contain a hidden field called the "NextFreeElement" field that tracks
17 what integer key should be used when a new element is appended. Under Zend PHP,
18 when an array is copied the NextFreeElement field of the new array will be
19 recomputed based on the keys it currently contains. Under HipHop VM, when an
20 array is copied the new array's NextFreeElement field is set to the same value
21 as the original array's NextFreeElement field.
23 (3) Array internal cursors
25 Under Zend PHP, if an array's internal cursor points to the position past the
26 last element and then a copy of the array is made, the copy will have its
27 internal cursor reset to point at the first element. Under HipHop VM, when a
28 copy of an array is made, the copy's internal cursor will always point to the
29 same position that the original array's internal cursor pointed to.
33 Under Zend PHP, foreach by value will modify the array's internal cursor under
34 certain circumstances. Under HipHop VM, foreach by value will never modify the
35 array's internal cursor.
37 (5) Foreach by reference
39 Under Zend PHP, the behavior of a foreach by reference loop can be
40 unpredictable if during iteration the next element of the array is unset, or if
41 the array variable is assigned to directly or through a reference, or if
42 copy-on-write causes the array to be copied. For such cases, HipHop VM's
43 behavior may differ from Zend PHP.
46 2. Classes and objects
48 (1) Exceptions thrown from destructors
50 Under HipHop VM, PHP exceptions thrown from destructors will be
51 swallowed while logging an error. Effectively, there is a try/catch enclosing
52 the body of the __destruct method. These exceptions are catchable under Zend
53 PHP outside of the __destruct method.
55 Fatals thrown from destructors will log an error, and prevent further PHP code
56 from executing as the fatal propagates. This includes other __destruct methods.
58 (2) __destruct behavior at end of request
60 Under Zend PHP, if an object is still live at the end of a request, its
61 __destruct method is invoked. By default, HipHop VM does not do this.
63 The EnableObjDestructCall runtime option can be used to make HipHop VM invoke
64 the __destruct method for objects that are live at the end of the request.
66 (3) Exceptions thrown from __toString()
68 Zend PHP does not allow exceptions to be thrown from __toString(). HipHop VM
69 does. Also, Zend PHP doesn't allow __toString() to return anything other than a
70 string. HipHop VM will just convert return value to string.
72 (4) __call/__callStatic() handling
74 This example gives inconsistent results in Zend PHP 5.5:
80 function __call($name, $arguments) { var_dump('G');}
81 function f4missing($a) {
82 B::f4missing(5); // __call checking happened at B
88 Under HipHop VM, both checking and invocation of __call() happen on class G.
90 (5) Object internal cursors
92 Under Zend PHP, objects have an internal cursor (similar to the array internal
93 cursor) that can be used to iterate over the object's properties. Under HipHop
94 VM, objects do not have internal cursors, and the next(), prev(), current(),
95 key(), reset(), end(), and each() builtin functions do not support objects.
100 (1) Case-insensitive constants
102 HipHop VM does not support case-insensitive constants, for example:
103 define('FOO', 123, true);
105 (2) get_defined_vars() and get_declared_classes()
107 HipHop VM may return variables/classes in a different order than Zend PHP.
111 Under Zend PHP, XMLWriter class and its functions returned different types of
115 function foo(XMLWriter $w) {}
116 $obj = new XMLWriter();
117 foo($obj); // <-- this one is actually okay
118 $obj2 = xmlwriter_open_memory(); // <-- just not this one
119 var_dump($obj, $obj2);
122 Under HipHop VM, they are the same.
124 (4) HipHop VM only supports preg_replace /e in limited cases.
125 Example unsupported case: phpt...bug24403
127 (5) Under Zend PHP, you can assign to $GLOBALS:
135 Under HipHop VM, this is not allowed or not working at present.
137 (6) All fatals prevent further PHP code from executing, including __destruct
138 methods. N.B.: exit() is a fatal.