Learn HACK with Real Code Examples
Updated Nov 20, 2025
Explain
Hack combines dynamic typing of PHP with optional static typing.
It allows gradual typing, meaning developers can mix typed and untyped code.
Designed for web development at scale, particularly within the Facebook ecosystem.
Core Features
Gradual typing system
Async programming with awaitables
Generics and type annotations
Shape types for structured data
Hack collections (vec, dict, keyset)
Basic Concepts Overview
Gradual typing (dynamic + static)
Collections (vec, dict, keyset)
Async programming with awaitables
Functions, classes, and traits
Shapes and generics for structured data
Project Structure
src/ - main Hack codebase
lib/ - reusable libraries
tests/ - unit and integration tests
docs/ - project documentation
configs/ - HHVM and server configurations
Building Workflow
Write Hack code with optional types
Run using HHVM interpreter or server
Test functions, classes, and async tasks
Compile or run scripts for production
Integrate with PHP code if necessary
Difficulty Use Cases
Beginner: small Hack scripts and functions
Intermediate: collections and async functions
Advanced: generics, shapes, and type-safe code
Expert: large-scale web application architecture
Migration: PHP to Hack gradual typing adoption
Comparisons
Adds static typing to PHP
Runs on HHVM instead of standard PHP engine
Better for large-scale web applications
Supports async and modern language features
Smaller ecosystem than mainstream PHP
Versioning Timeline
2014 – Hack created by Facebook
2015 – HHVM integration stabilized
2016 – Async programming and collections introduced
2018 – Generics, shapes, and typechecker improvements
2020s – Ongoing maintenance and ecosystem updates
Glossary
Gradual typing: mix of static and dynamic types
HHVM: HipHop Virtual Machine for Hack/PHP
Collections: vec, dict, keyset types
Awaitable: async result to be awaited
Shape: structured data type with fixed fields