PHP 5.4 and Facebook Hiphop compatibility
Asked Answered
S

2

8

I was wondering does anyone know which of the features in PHP 5.4 are not supported in Facebook's Hiphop library. There's some questions on the Hiphop github wiki, such as this one, that very vaguely state :

HipHop does not currently support all PHP 5.4 features.

At the moment I just have to assume, for working purposes, all new features are not compatible as none are specified to work, if anyone has any insight on this that would be great, thanks in advance.

Slaby answered 25/10, 2012 at 15:0 Comment(0)
V
8

Stay away from the following:

Trait Declaration:

trait vehicleInfo {
    function getSpeed() { /*1*/ }
    function getWheels() { /*2*/ }
}

class Car extends Vehicle {
    use vehicleInfo;
    /* ... */
}

class Motorcycle extends Vehicle {
    use vehicleInfo;
    /* ... */
}

PHP 5.4 Array Instantiation:

$array = [
    "name" => "John Smith",
    "job" => "Basketweaver",
];

Function array dereferencing:

function small_numbers() {
    return array (0, 1, 2);
}

echo small_numbers()[0];

Class Member Access on Instantiation:

(new Foo)->bar();
Visor answered 25/10, 2012 at 15:22 Comment(3)
Thanks for the reply and the examples, I'll stay away from them. Do you know if any of these are incompatible with HipHop-php? Or ones that are if that's a shorter list!Slaby
All of these updates are syntactic optimizations. You don't have to use them to write code, they just make your life a little easier (so staying away from them won't hurt you in the long run).Visor
We just started testing HHVM on a long running project. I haven't seen it complain about traits or 5.4 array instantiation but it does complain about using references in a foreach loop ie: foreach ($foo as &$bar). If anyone has an up to date comprehensive list, I'd love to see it.Larsen
H
1

HipHop currently supports all of the features Daniel Li pointed out, except possible binary numbers. In fact, HipHop supported closures for years. The runtime is constantly improving, so keep an eye out in the future for a feature you're waiting for to show up.

If in doubt, and you have the time, just try using a feature and seeing if it works or not.

akrieger@vb:~/www$ hhvm features.php
2
akrieger@vb:~/www$ cat features.php
<?php

trait vehicleInfo {
    function getSpeed() { /*1*/ }
    function getWheels() { return [1,2,3,4]; }
}

class Vehicle {}

class Car extends Vehicle {
    use vehicleInfo;
    /* ... */
}

class Motorcycle extends Vehicle {
    use vehicleInfo;
    /* ... */
}

$getMotorcycleWheels = function() {
  return (new Motorcycle())->getWheels();
};

echo $getMotorcycleWheels()[1];
echo "\n";
akrieger@vb:~/www$
Helmholtz answered 21/6, 2013 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.