PHPackages                             hhvm/hhvm-autoload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hhvm/hhvm-autoload

AbandonedArchivedComposer-plugin[Utility &amp; Helpers](/categories/utility)

hhvm/hhvm-autoload
==================

v3.3.2(3y ago)34673.4k↓30.6%20[3 issues](https://github.com/hhvm/hhvm-autoload/issues)[1 PRs](https://github.com/hhvm/hhvm-autoload/pulls)20MITHack

Since Feb 15Pushed 3y ago16 watchersCompare

[ Source](https://github.com/hhvm/hhvm-autoload)[ Packagist](https://packagist.org/packages/hhvm/hhvm-autoload)[ RSS](/packages/hhvm-hhvm-autoload/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (57)Used By (20)

HHVM-Autoload
=============

[](#hhvm-autoload)

The autoloader for autoloading classes, enums, functions, typedefs, and constants on HHVM.

[![Continuous Integration](https://github.com/hhvm/hhvm-autoload/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/hhvm/hhvm-autoload/actions/workflows/build-and-test.yml)

Usage
=====

[](#usage)

1. Add an `hh_autoload.json` file (see section below)
2. `composer require hhvm/hhvm-autoload`
3. Require the autoload file from your entrypoint functions using `require_once (__DIR__ . '(/..)(repeat as needed)/vendor/autoload.hack');`
4. Call `Facebook\AutoloadMap\initialize()` to register the autoloader with hhvm.
5. To re-generate the map, run `vendor/bin/hh-autoload`, `composer dump-autoload`, or any other command that generates the map

Configuration (`hh_autoload.json`)
==================================

[](#configuration-hh_autoloadjson)

A minimal configuration file is:

```
{
  "roots": [ "src/" ]
}
```

This will look for autoloadable definitions in `src/`, and also look in `vendor/`. Projects in `vendor/` are only processed if they also contain a `hh_autoload.json` file.

Previously we also supported projects without `hh_autoload.json` by simulating Composer's autoload behavior, but we no longer do because that mostly applied to PHP files which HHVM can no longer parse.

The following settings are optional:

- `"extraFiles": ["file1.hack"]` - files that should not be autoloaded, but should be `require()`ed by `vendor/autoload.hack`. This should be needed much less frequently than under Composer
- `"includeVendor": false` - do not include `vendor/` definitions in `vendor/autoload.hack`
- `"devRoots": [ "path/", ...]` - additional roots to only include in dev mode, not when installed as a dependency.
- `"relativeAutoloadRoot": false` - do not use a path relative to `__DIR__` for autoloading. Instead, use the path to the folder containing `hh_autoload.json` when building the autoload map.
- `"failureHandler:" classname` - use the specified class to handle definitions that aren't the Map. Defaults to none.
- `"devFailureHandler": classname` - use a different handler for development environments. Defaults to the same value as `failureHandler`.
- `"parser:" any of [ext-factparse]"` - select a parser to use, but there is only one valid option. Defaults to a sensible parser.
- `"useFactsIfAvailable": false` - use ext-facts (HH\\Facts...) to back Facebook\\AutoloadMap\\Generated\\map() instead of a codegenned dict. See *Use with HH\\Facts* for more information about this mode.

Use In Development (Failure Handlers)
=====================================

[](#use-in-development-failure-handlers)

When you add, remove, or move definitions, there are several options available:

- run `composer dump-autoload` to regenerate the map
- run `vendor/bin/hh-autoload` to regenerate the map faster
- specify `devFailureHandler` as `Facebook\AutoloadMap\HHClientFallbackHandler`
- specify a custom subclass of `Facebook\AutoloadMap\FailureHandler`
- use a filesystem monitor such as [watchman](https://facebook.github.io/watchman/) to invoke one of the above commands when necessary

`Facebook\AutoloadMap\HHClientFallbackHandler` is probably the most convenient for Hack development.

HHClientFallbackHandler
-----------------------

[](#hhclientfallbackhandler)

If you are working in Hack, this handler will remove the need to manually rebuild the map in almost all circumstances.

It asks `hh_client` for definitions that aren't in the map, and has the following additional behaviors:

- it is disabled if the `CI`, `CONTINUOUS_INTEGRATION`, or `TRAVIS`environment variables are set to a Truthy value; this is because it is not a recommended approach for production environments, and you probably want your automated testing environment to reflect production
- results are cached in both APC and a file in vendor/, if vendor/ is writable

You can override these behaviors in a subclass.

Custom Handlers
---------------

[](#custom-handlers)

Information you may need is available from:

- `Facebook\AutoloadMap\Generated\build_id()`: this is unique ID regenerated every time the map is rebuilt; it includes the date, time, and a long random hex string. If your failure handler has a cache, it most likely should be invalidated when this changes, for example, by including it in the cache key.
- `Facebook\AutoloadMap\Generated\map()`: the autoload map
- `Facebook\AutoloadMap\Generated\root()`: the directory containing the project root, i.e. the parent directory of `vendor/`

Use with HH\\Facts
==================

[](#use-with-hhfacts)

HHVM 4.109 introduced ext-facts and ext-watchman. Unlike the static pre-built autoloader which is built into a [repo authoratative](https://docs.hhvm.com/hhvm/advanced-usage/repo-authoritative) build, this native autoloader works incrementally and is suitable for autoloading in your development environment. For more information about setting up this autoloader, see the [blog post](https://hhvm.com/blog/2021/05/11/hhvm-4.109.html) for hhvm 4.109.

When using a native autoloader (either the repo auth or ext-facts autoloader), you do not need hhvm-autoload to require classes/functions/types/constants at runtime. If you (and your vendor dependencies) do not call any functions in the `Facebook\AutoloadMap` namespace, other than `Facebook\AutoloadMap\initialize()`, you don't need hhvm-autoload anymore. In that case, you could drop this dependency and remove the calls to `initialize()`. If you are using other functions, like `Facebook\AutoloadMap\Generated\map()`, you'd still need the vendor/autoload.hack file that hhvm-autoload generates.

Hhvm-autoload supports outputting a vendor/autoload.hack file which forwards all queries to ext-facts. `Facebook\AutoloadMap\Generated\map_uncached()` will always be up to date in this mode, since `HH\Facts` is always up to date. `Facebook\AutoloadMap\Generated\map()` is memoized (within a request), since some code may rely on getting the same result from multiple calls. You can enable this mode by adding `"useFactsIfAvailable": true` to the hh\_autoload.json config file. Hhvm-autoload will emit a shim file instead of a full map. This option is ignored if `HH\Facts\enabled()` returns false, or when `--no-facts` is passed to `vendor/bin/hh-autoload`. We recommend passing `--no-facts` when building for production (specifically repo auth mode). Returning a hardcoded dict is faster than asking `HH\Facts`.

Important to note. Autoloading with a native autoloader does not respect hh\_autoload.json. The repo auth autoloader allows any code to use any symbol. The facts autoloader honors the configuration in .hhvmconfig.hdf instead. Make sure that the configuration in hh\_autoload.json and .hhvmconfig.hdf match.

How It Works
============

[](#how-it-works)

- A parser (FactParse) provides a list of all Hack definitions in the specified locations
- This is used to generate something similar to a classmap, except including other kinds of definitions
- The map is provided to HHVM with [`HH\autoload_set_paths()`](https://docs.hhvm.com/hack/reference/function/HH.autoload_set_paths/)
- If a native autoloader is registered, this autoloader will intentionally not register itself. So calling `Facebook\AutoloadMap\initialize()` in repo auth mode or when the facts based autoloader is registered is a noop.

Contributing
============

[](#contributing)

We welcome GitHub issues and pull requests - please see CONTRIBUTING.md for details.

License
=======

[](#license)

hhvm-autoload is [MIT-licensed](LICENSE).

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community41

Growing community involvement

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 76.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Total

56

Last Release

1449d ago

Major Versions

v1.8 → v2.02019-02-07

v2.0.13 → v3.0.02020-02-07

v2.0.x-dev → v3.1.62020-11-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/66d33e29918fd8cc713997dbbe03cb86e2aefbdc6736637641cdffed2f22accb?d=identicon)[fredemmott](/maintainers/fredemmott)

---

Top Contributors

[![fredemmott](https://avatars.githubusercontent.com/u/360927?v=4)](https://github.com/fredemmott "fredemmott (218 commits)")[![lexidor](https://avatars.githubusercontent.com/u/31805625?v=4)](https://github.com/lexidor "lexidor (20 commits)")[![jjergus](https://avatars.githubusercontent.com/u/2483917?v=4)](https://github.com/jjergus "jjergus (15 commits)")[![simonwelsh](https://avatars.githubusercontent.com/u/125915?v=4)](https://github.com/simonwelsh "simonwelsh (7 commits)")[![TJ09](https://avatars.githubusercontent.com/u/829579?v=4)](https://github.com/TJ09 "TJ09 (6 commits)")[![karoun](https://avatars.githubusercontent.com/u/870701?v=4)](https://github.com/karoun "karoun (5 commits)")[![azjezz](https://avatars.githubusercontent.com/u/29315886?v=4)](https://github.com/azjezz "azjezz (4 commits)")[![kmeht](https://avatars.githubusercontent.com/u/1120478?v=4)](https://github.com/kmeht "kmeht (3 commits)")[![alexeyt](https://avatars.githubusercontent.com/u/727402?v=4)](https://github.com/alexeyt "alexeyt (2 commits)")[![jesseschalken](https://avatars.githubusercontent.com/u/1559204?v=4)](https://github.com/jesseschalken "jesseschalken (1 commits)")[![HRMsimon](https://avatars.githubusercontent.com/u/7907670?v=4)](https://github.com/HRMsimon "HRMsimon (1 commits)")[![GroovyCarrot](https://avatars.githubusercontent.com/u/5589906?v=4)](https://github.com/GroovyCarrot "GroovyCarrot (1 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![Atry](https://avatars.githubusercontent.com/u/601530?v=4)](https://github.com/Atry "Atry (1 commits)")[![aloiret](https://avatars.githubusercontent.com/u/1227963?v=4)](https://github.com/aloiret "aloiret (1 commits)")

---

Tags

autoloaderhacklanghhvm

### Embed Badge

![Health badge](/badges/hhvm-hhvm-autoload/health.svg)

```
[![Health](https://phpackages.com/badges/hhvm-hhvm-autoload/health.svg)](https://phpackages.com/packages/hhvm-hhvm-autoload)
```

###  Alternatives

[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[mglaman/composer-drupal-lenient

1317.4M15](/packages/mglaman-composer-drupal-lenient)[drupal/core-composer-scaffold

A flexible Composer project scaffold builder.

5341.9M446](/packages/drupal-core-composer-scaffold)[drupal/core-project-message

Adds a message after Composer installation.

2122.6M172](/packages/drupal-core-project-message)[olvlvl/composer-attribute-collector

A convenient and near zero-cost way to retrieve targets of PHP 8 attributes

184108.8k8](/packages/olvlvl-composer-attribute-collector)[lullabot/drainpipe

An automated build tool to allow projects to have a set standardized operations scripts.

41716.4k2](/packages/lullabot-drainpipe)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
