|HHVM Improves Type Inference|
|Written by Kay Ewbank|
|Friday, 19 January 2018|
There's a new version of Hip Hop Virtual Machine, an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM was originally developed at Facebook to provide a way to convert PHP script to C++ so it could be compiled and run on web servers.
HHVM uses just-in-time (JIT) compilation to combine good performance with a flexible development environment. HHVM supports Hack, PHP 5 and the major features of PHP 7.
This release is important as it is the last release to have PHP 5 as a main focus. The developers at Facebook said in September that HHVM would not be developed to target PHP 7. Their reasoning was that:
"the HHVM team believes that we have a clear path toward making Hack a fantastic language for web development, untethered from its PHP origins. We’d do ourselves and our users a disservice by positioning HHVM as an uncommon, less well-documented, less compatible PHP7 runtime."
On this basis, while they expect Hack and PHP7 to retain a good deal of overlap for the time being, and many users may find success using the runtimes interchangeably in the short term, the team does not intend HHVM to be the runtime of choice for developers with pure PHP7 code who are using PHP's more recent additions. Going forward, the Facebook developers recommend developers migrate to Hack or PHP7.
Hack is Facebook's development onward from HHVM. Hack is a programming language for HHVM that is statically typed. Hack has been in use at Facebook long enough for the the entire codebase to have been moved across to it and there is an open source version complete with HHVM. There are also some tools included to make conversion easier.
In practical terms for this release of HHVM, 3.24, the improvements start with better handling of Hack code. Reference arguments must now be marked at the call site, not just at the function declaration. The team has extended HHAST to automate migrations.
Support has been added for 'using' blocks as an alternative to destructors. “Using” blocks provide a mechanism to limit an object to a particular scope, invoking code on scope exit, without using destructors.
Type inference and type checking for lambdas is another area that has been improved.
XHP is another area to have received improvements. The XHP attribute spread operator has been added, and the developers have improved the typing of XHP attributes and children.
Other improvements are clearer error messages, and improved handling of multiple debuggers (e.g. hphpd + xdebug).
or email your comment to: email@example.com