Design Problems in a PHP Codebase

Hack was developed by Facebook’s language-tools team, publicly released with open source code on March 20, 2014, and run on the HipHop Virtual Machine, HHVM. Julien Verlaguet, Eugene Letuchy, Gabriel Levi and Erik Meijer were among the core team named in the release announcement. It was a collaborative engineering project primarily intended for Facebook’s large existing PHP codebase.

The team wanted to detect type errors earlier while preserving a workflow in which developers could edit code and immediately observe the resulting web page. Rewriting a large body of existing software was costly, so migration proceeded by gradually introducing type information. In the announcement, Facebook said it had converted nearly all of its own PHP code during the preceding year.

References: [1]

Static Checking and the Virtual Machine

Hack programs still needed a runtime. HHVM 3.0.0, released on March 28, 2014, explicitly included Hack support. Its announcement explained that hh_server and hh_client, which supplied type feedback, were separate from the virtual machine. Although distributed with the binary packages, they required configuration and startup. Installing the runtime and enabling development-time checks were related but distinct steps.

The type checker retained program information in a local resident service and updated its analysis when files changed. Engineers therefore did not have to analyze the whole project from scratch after each edit. The early implementation sought to make checking part of everyday editing, allowing problems to be identified before they surfaced in a running web page.

References: [2] [1]

Types at Function Boundaries

A small function illustrates the approach: function bump(int $n): int { return $n + 1; }. The int before the parameter requires an integer input, while the int after the colon specifies an integer result; bump(4) returns 5. Passing a string to this interface gives the type checker a clear constraint to test.

Annotations concentrated on function boundaries and object members. The first formal specification in 2015 covered strict mode and required named functions to declare parameter and result types. Local variables could be inferred from expressions, but inference did not cross function boundaries. Callers could therefore understand an interface without developers having to annotate every temporary variable.

References: [3]

Nullable Types and Generics

A question mark denotes a nullable type. For example, ?string allows either a string or null, making the possibility of no result part of the interface. A query returning ?string cannot simply be treated as always producing a string. The annotation makes the conditional branch visible while callers write their subsequent handling.

Generics preserve relationships between containers and their elements. The specification’s Stack<T> uses the same type parameter for its internal array, the argument of push and the result of pop. In Stack<int>, retrieved elements retain their integer type and a floating-point input is rejected. This avoids separate implementations for integer and string stacks while making checking easier than treating every element as an undifferentiated dynamic value.

References: [3]

Conversion Tools Connect the Design to Real Projects

The first Hack Developer Day, on April 9, 2014, presented language design alongside migration practice. Verlaguet introduced the language and checker, while Josh Watzman demonstrated conversion. Hackificator helped change source-file markers, and other tools attempted to introduce soft type annotations before progressing toward stricter checks. The report acknowledged that some steps remained manual.

The event also demonstrated collections, anonymous functions, async/await and the FBIDE development environment. FBIDE compiled the type checker to JavaScript to provide browser-side analysis and completion. Early promotion thus supplied both syntax and the tools and procedures for gradually converting existing code.

References: [4]

A Formal Specification after the Release

On February 19, 2015, Joel Marcey announced the first formal Hack language specification. Application developers already had usage documentation; the specification additionally addressed language implementers and authors of conformance tests. It organized syntax and semantics with the help of the existing PHP specification, consolidating experience from the implementation.

The first specification focused on strict mode and did not encompass the entire runtime library, a scope distinct from the gradual mixing of old and new code supported during migration in 2014. Hack’s early development connected explicit function interfaces, static analysis and incremental conversion to established PHP engineering.

References: [5] [3]