rfc:autoload_classmap
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:autoload_classmap [2021/03/15 17:20] – marandall | rfc:autoload_classmap [2021/04/06 05:32] (current) – marandall | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Autoload Classmap ====== | ====== PHP RFC: Autoload Classmap ====== | ||
- | * Version: | + | * Version: |
* Date: 2021-03-15 | * Date: 2021-03-15 | ||
- | * Author: Mark Randall, | + | * Author: Mark Randall, |
- | * Status: | + | * Status: |
* Target: 8.1 | * Target: 8.1 | ||
Line 12: | Line 12: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC would introduce a new mechanism for autoloading classes via an internal classmap loader, that can be configured once per request by passing an associative array mapping | + | This RFC would introduce a new mechanism for autoloading classes via an internal classmap loader, that can be configured once per request by passing an associative array mapping |
- | This proposal is written with the names autoload_xx rather than spl_autoload_ as an independent RFC will be proposed to alias the existing SPL autoload functions to simply autoload_xx. If that RFC fails, but this one passes, the implementation would use spl_autoload_xx names instead. | + | This proposal is written with the names autoload_xx rather than spl_autoload_ as an independent RFC will be proposed to alias the existing SPL autoload functions to simply autoload_xx |
<code php> | <code php> | ||
Line 30: | Line 30: | ||
The autoloader will: | The autoloader will: | ||
* Always check the classmap first if it is set. | * Always check the classmap first if it is set. | ||
- | * (If Found) Trigger a TypeError if the relevant | + | * (If Found) Trigger a TypeError if the key' |
- | * (If Found) Trigger an Error if the relevant class is not defined after including the file specified in the key value. | + | * (If Found) Use the REQUIRE mechanism. |
- | * (If Found) Use the REQUIRE_ONCE mechanism. | + | * (If Found) Trigger an Error if the relevant class is not defined after including the file specified in the classmap. |
If the classmap is not set, or the class name cannot be found within the classmap, the autoloader will continue to perform its traditional behaviour of iterating over the functions specified by spl_autoload_register. | If the classmap is not set, or the class name cannot be found within the classmap, the autoloader will continue to perform its traditional behaviour of iterating over the functions specified by spl_autoload_register. | ||
+ | |||
+ | ===== Performance ===== | ||
+ | |||
+ | Testing suggests that autoloading through an internal classmap delivers around 5% performance increase vs a userland function call (e.g. composer). | ||
+ | |||
+ | This is 5% of the cost of the autoloading, | ||
+ | |||
+ | Average for internal classmap was 0.295 vs 0.313 for spl_autoload_register representing 5.9% difference (in autoload performance only). | ||
+ | |||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== |
rfc/autoload_classmap.1615828813.txt.gz · Last modified: 2021/03/15 17:20 by marandall