Unsupported PHP Features in Hack

Table of Contents

Note:

These are features that the Hack language does not support (i.e., the Hack type checker will give you an error if you try to use them). However, HHVM supports these features just fine when using PHP code.

While Hack is quite symbiotic with the PHP language, there are some PHP features that are not supported by Hack and the type checker. Here is a non-exhaustive list:

  • Rarely used language constructs including goto, if:...endif;.

  • AND, OR, XOR operators. Use &&, ||, ^ instead.

  • References (e.g., function foo(&$x))

  • The @ symbol to silence errors.

  • Mixing static and instance function calls (A::foo() vs. $a->foo() )

  • break N and continue N

  • Dynamic features such as eval and $$x

  • "Undefined" variables

  • Globals (e.g., global $x;)

  • Variable variables (e.g. $a = "hello"; $$a = "world"; echo "$a + $hello";)

  • Writing list(, $b) = array(3,4) is not allowed. Instead use $_, i.e.: list($_, $b) = array(3, 4).

  • Using a string directly as a function is not supported (e.g., $func = 'myFunc'; $func(1,2);). Instead wrap the string with function fun() (e.g., $func = fun('myFunc'); $func(1, 2);).

  • ArrayAccess. Hack allows such objects; it just will not recognize them as arrays. Not only is ArrayAccess an "interesting" interface (e.g., having a null key means "append"), but supporting it causes a lot of strange edge cases such as needing more complicated checks around instance variable initialization. Since ArrayAccess is typically used to migrate old code, it is not supported for now; support could happen if a compelling case arose.

  • Case-insensitive function calls (the Hack typechecker is case-sensitive).

  • Mixed HTML and Hack code. Use a templating engine or XHP.

To Top