Home > Article > Backend Development > The Future of PHP: Facebook Hack_PHP Tutorial
Facebook released a new programming language Hack this year. No matter how you analyze it, this language is similar to the popular PHP. A large number of its features, such as static typing, are consistent with what PHP developers have long requested. Putting aside the syntax, Hack is actually not PHP. Hack runs on Facebook's virtual machine HHVM, while its competitors run on the traditional PHP Zend engine.
Why did Facebook build Hack?
First of all, Facebook's internal code is written in PHP. At the same time, Facebook can enable many new developers to use PHP because the language is easy to learn and use. Of course, Facebook's PHP code may be converted to C derivatives before being pushed to production environments. The crux of the matter is that Facebook relies heavily on the PHP language to attract new talent and improve developer efficiency.
Strict Type
Unfortunately, PHP is impossible to perform at the scale of Facebook. Because PHP is a loosely typed language, many type errors may not be discovered at runtime. This means Facebook has to write a lot of tests early on to perform type error checking, or spend more time rebuilding post-launch runtime errors. To solve this problem, Facebook added strict typing to attack runtime return types. Strict typing eliminates the need for many relevant unit tests, while also incentivizing developers to catch type-related bugs early in the development process.
Transient type checking
In order to make it easier to catch errors during development, Facebook's HHVM engine includes a type of check server that monitors Hack code when running locally. Developers' code editors and IDEs can use this type checking server to immediately report syntax or type-related errors during code development.
What about existing PHP code?
Most existing PHP code will run on Facebook's HHVM engine, which is necessary because Facebook's existing code base is primarily PHP code. There are some anomalies in Hack code. After all, it is not equivalent to traditional PHP. For example, some language features (such as variables) and Zend extensions are still not supported. As time goes by, HHVM will also implement parity verification with the Zend engine as soon as possible.
In addition, the Hack language created by Facebook is gradually migrating from traditional PHP code.
Does this mean PHP is "dead"?
If Hack is that good, does this mean PHP's days are numbered? The answer is of course: NO! Traditional PHP Zend is managed and reviewed by a specialized organization. Any new features must be reviewed and voted by members of the organization before they can be announced. Such voting is 100% fair and open.
But Hack is very good. Hack has many unique functions of its own, so it will never become a traditional PHP language. Facebook's HHVM engine has better performance than the Zend engine, and it has more internal developers dedicated to constantly making the HHVM engine better.
This does not mean that PHP’s Zend engine will disappear. Zend and HHVM engines can and will coexist. Competition is a good thing, and I hope both Zend and HHVM will benefit from each other's strengths.
Is Facebook responsible?
Hack is a product of Facebook, which mainly originated from Facebook engineers. While the public now expects it to be announced, Hack and HHVM still rely heavily on continued investment and engagement with Facebook.
Future
Due to the superiority of Hack and HHVM, I think to some extent, Hack is the future of PHP.