Hack 语言学习/参考---1.2 Hack Background

2023-07-30,,

Hack Background

Facebook was initially built with PHP. Parameters and return types were specified in comments. Parsers could use this to create documentation. But type-checking was non existent.

<?php
/**
* Wraps a name in a box
*
* @param raw-str $name
* @return html-str
*/
function say_hello($name) {
return "<div class=\"box\"<hello ".htmlize($name)."</div>";
}

In 2009, a PHP compiler called HipHop was released. In 2010, minor changes to the PHP language were introduced by the HPHP team to improve development time and provide basic type safety. The changes were XHP and parameter type constraints.

<?php
/**
* Wraps a name in a box
*
* @return xhp
*/
function say_hello(string $name) {
return <div class="box"<Hello {$name}>/div>;
}

In 2012, Facebook engineering teams started exploring the idea of annotating return types. And the Hack language was born...

Hack 语言学习/参考---1.2 Hack Background的相关教程结束。

《Hack 语言学习/参考---1.2 Hack Background.doc》

下载本文的Word格式文档,以方便收藏与打印。