Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

237 lines (166 sloc) 6.952 kB
<h2>Inconsistencies between PHP and HipHop</h2>
These are the known inconsistencies between current HipHop and PHP.
1. Operators
(1) Arithmetic
In PHP, the addition, subtraction, or multiplication of two integers will
produce a floating-point value if the result overflows the integer type. In
Hiphop, the addition, subtraction, or multiplication of two integers will
always produce an integer value; if the result overflows the integer type, the
upper bits of the result will be truncated.
(2) Foreach by value
In PHP, foreach by value will modify the array's internal cursor under certain
circumstances. In HipHop, foreach by value will never modify the array's
internal cursor.
(3) Foreach by reference
In PHP, if during a foreach by reference loop the next element of the array is
unset, the foreach loop may fail to visit all of the elements in the array.
Under HipHop, foreach by references loops that do not break early make the
following guarantees:
a) If an original element is not deleted, the loop will visit it exactly
once.
b) If an element is appended and is not deleted, the loop will visit it
exactly once.
c) An original element or an appended element will not be visited if it is
deleted during a previous iteration.
d) The loop will visit all elements in order, original elements first
followed by appended elements.
(4) instanceof
In PHP, [constant] instanceof [class name] will cause a fatal.
In HipHop, there is no special case for constants and the expression's value is
false.
(5) Internal array cursors
In PHP, if an array's internal cursor points past the last element and then a
copy of the array is made, the copy will have its internal cursor reset to
point at the first element. In HipHop, when a copy of an array is made, the
copy's internal cursor will always point to the same element that the original
array's internal cursor pointed to.
(6) Next free integer key for arrays
Arrays contain a hidden field called the "NextFreeElement" field that tracks
what integer key should be used when a new element is appended. In PHP, when an
array is copied the NextFreeElement field of the new array is recomputed based
on the keys it currently contains. In HipHop, when an array is copied the new
array's NextFreeElement field is set to the same value as the original array's
NextFreeElement field.
2. Classes and objects
(1) Exceptions thrown from destructors
In HipHop, exceptions and fatals thrown from destructors will be swallowed
while logging an error. Effectively, there is a try/catch enclosing the body
of the __destruct method. These exceptions are catchable in PHP outside of the
__destruct method.
(2) Global variable's destructor
In HipHop, global variables are not destructed at end of web requests or
program execution if memory manager is enabled (default). They are garbage
collected by memory sweeping as a whole for performance reason and for
preventing memory leaks if circular reference exists between two or more
global variables. So destructors of global objects are not called.
In PHP, global variables are destructed before a web page responds. Therefore,
output from their destrcutors will be part of the HTTP response.
(3) Exceptions thrown from __toString()
PHP doesn't allow them. HipHop does. Also, PHP doesn't allow __toString() to
return anything other than a string. HipHop will just convert return value to
string.
(4) unset
In PHP, a data member that is unset will not appear at all in vardump or
serialize. Also, unsetting a data member and then resetting it will alter its
order in foreach iterations.
In HipHop, it will still appear in vardump or serialize as null. It will
not appear in foreach iteration, so it's consistent with PHP. When unsetting
a data member and then resetting it, it's order is not altered in foreach
iteration. When unsetting then resetting to NULL, HipHop will be confused to
think the property is still not present (bug).
(5) $this handling of static method
In PHP, $this may be passed into an unrelated class's static method. Here's an
example,
<?php
class b {
public function bar() {
var_dump($this); // <-- $this is actually class "c" object
$this->baz();
}
}
class c { // <-- note that "c" has nothing to do with "b"
public $x = 2;
public function foo() {
b::bar();
}
public function baz() {
echo "Hello!\n";
}
}
$obj = new c;
$obj->foo();
In HipHop, $this will be NULL when doing this.
(6) __call/__callStatic() handling
These 2 examples give inconsistent results in PHP 5.3:
<?php
class B {
}
class G extends B {
function __call($name, $arguments) { var_dump('G');}
function f4missing($a) {
B::f4missing(5); // __call checking happened at B
}
}
$g = new G();
$g->f4missing(3);
<?php
class B {
function __call($name, $arguments) { var_dump('B');}
}
class G extends B {
function __call($name, $arguments) { var_dump('G');}
function f4missing($a) {
B::f4missing(5); // G::__call() was called actually!
}
}
$g = new G();
$g->f4missing(3);
In HipHop, both checking and invocation of __call() happen on class G.
3. Eval Issues
(1) eval
Is only supported in limited circumstances.
Example unsupported case: phpt...bug21960
(2) create_function
is only supported with literal arguments
Example unsupported case: phpt...bug22690
(3) preg_replace /e
is only supported in limited cases.
Example unsupported case: phpt...bug24403
4. $GLOBALS is not an ordinary variable:
In php you can assign to $GLOBALS
$GLOBALS = 0;
$x = $GLOBALS - 5;
$g = $GLOBALS;
$g['x'] = 3;
In HipHop, this is not allowed or not working.
5. Constants
(1) Dynamically declared constants
These are not supported, e.g.
define($name, $value);
(2) Case-insensitive constants
These are not supported, e.g.
define('FOO', 123, true);
6. Misc
(1) get_defined_vars() and get_declared_classes()
Can return variables/classes in different order from PHP's.
(2) uninitialized variables
If an uninitialized variable is being used before it's assigned with a value,
and this variable is inferred as integers, it will be 0, instead of null.
(3) call_user_func() and call_user_func_array()
PHP doesn't respect pass-by-reference parameters and return value. HipHop does.
PHP doesn't allow func_get_args() to be used as arguments of these two
functions. HipHop does.
(4) XMLWriter
In PHP, XMLWriter class and its functions returned different types of objects,
<?php
function foo(XMLWriter $w) {}
$obj = new XMLWriter();
foo($obj); // <-- this one is actually okay
$obj2 = xmlwriter_open_memory(); // <-- just not this one
var_dump($obj, $obj2);
foo($obj2);
In HipHop, they are the same.
(5) GOTO statement
In PHP, jumping to a GOTO label across try/catch blocks is allowed. In HipHop,
it isn't.
(6) ReflectionProperty::setAccessible() is not supported.
Jump to Line
Something went wrong with that request. Please try again.