• Increase font size
  • Default font size
  • Decrease font size
Home Software Automap Automap FAQ

Automap FAQ

E-mail Print
Read : 1,442 times
(2 votes, average 5.00 out of 5)

1. How does Automap differ from other PHP autoloaders ?
2. Why do map files also reference functions and constants ?
3. What are the relationships between Automap and PHK ?

1 - How does Automap differ from other PHP autoloaders ?

Most PHP autoloaders available today follow the PSR conventions and, as such, belong to the family of path-based autoloaders. A path-based autoloader uses the symbol name and namespace to locate the script file defining the symbol.

The main issue with path-based autoloaders is performance. As resolving a symbol implies a lot of interaction with the file system (stat() calls), symbol resolution is quite slow, especially when considering framework-based applications potentially generating thousands of class resolutions per request. In these cases, the autoloader can easily take more than 50 % of the overall execution time. Unfortunately, improving performance of such autoloaders is complex because, by nature, filesystem access will always slow them down.

Unlike path-based autoloaders, Automap is a map-based autoloader. Such an autoloader uses a pre-built map to locate the script defining a given symbol. The CPU-intensive part is done offline, when building the map. At runtime, there's no need to search the filesystem again, making it much faster.

This page contains a detailed list of pros and cons of both autoloader families.

2 - Why do map files also reference functions and constants ?

The map creation process extracts functions and constants, as well as classes, because, in theory, there is no reason to restrict autoloading to classes. So,PHP can be extended in the future to support function and constant autoloading.

Actually, the main argument against extending the autoload mechanism to functions and constants is its incompatibility with the PSR conventions, especially the 'one symbol per file' constraint. Which, in turn, is justified by the use of a path-based autoloader. If we eliminate this constraint, PHP autoloading can be easily extended without introducing any BC break.

For all these reasons, Automap was designed from the beginning to consider classes as one symbol type among others. That's why, in the documentation, we talk about symbols instead of classes.

3 - What are the relationships between Automap and PHK ?

PHK is a PHP package system. It allows to gather several files in a single package file, and then distribute and run it as is.

Both Automap and PHK projects have strong relationships, as every PHK package transparently includes an Automap autoloader, and the Automap manager/runtime is distributed as a PHK package ! Despite of these relationships, Automap can be used out of PHK packages.

The Automap build and runtime codes are contained in one file (named automap.phk). Technically, this file is a PHK package but the user does not have to care about this.


Please login or register to add a comment