Other Features: Introduction

In addition to the primary topics covered in this user guide, Hack has other noteworthy features that deserve attention.

  • Constructor parameter promotion allows you to reduce class property boilerplate in your code.
  • Trait and interface requirements allow you to restrict what classes can use a trait or implement an interface.
  • Enhanced autoloading enhances the normal class autoloading process with the autoloading of Hack (and PHP) functions and constants, as well as Hack traits.
  • Variadic functions allow functions to take a variable number of arguments. They are supported like in PHP, but must be explicitly marked variadic, enhancing type safety and checking.
  • The placeholder variable $_ allows for variables of any type to be assigned to it with the agreement that the variable will not be used after assignment, such as when iterating over key/value pairs where you don't care about the value.