Autoloads and class naming
This page is for application creators who add PHP classes. Exponential finds classes through generated class maps; a class that is not in the map does not exist as far as the application is concerned.
Contents
The class maps
| Map | Covers | Made by |
|---|---|---|
autoload/ezp_kernel.php | kernel classes | shipped; regenerated by kernel developers |
autoload/ezp_extension.php | classes of every extension | php bin/php/ezpgenerateautoloads.php -e |
| Composer's autoloader | vendor/ libraries | composer install |
The generator scans the extension directories (including AdditionalExtensionDirectories[]) for PHP files and lists
each class with its file (10.7 Class autoloads).
Regenerating
php bin/php/ezpgenerateautoloads.php -eRun it after adding, renaming or moving a class. Under Velocity, workers keep the map they started with: restart them
(exp:velocity deploy regenerates and restarts in order). A new class that settings name (a handler, a datatype) must be
deployed before the setting that uses it goes live.
Naming
- New classes start with a prefix of your organization or your extension:
acmeDemoList,acmeDemoListService.sevenxandexpare the prefixes of 7x and the Exponential project:sevenxis 7x's official public PHP code prefix (a class name cannot start with a digit, so "7x" cannot be one), and 7x usesexpwith intent for work it assigns to the Exponential project and the Exponential Foundation. Useexponly for code you contribute to the project. See Naming prefixes: sevenx and exp. - One class per file; file name in lower case:
classes/acmedemolist.php. - Never reuse a kernel name (
eZ...) for a new class; never rename an existing kernel identifier.
See Layering and naming and Coding standards.
Namespaced classes
Runnable classes (commands, cronjob parts, module views) use namespaces: Exponential\Command\Extension\<Ext>\<Name>,
Exponential\Cronjob\Extension\<Ext>\<Name>, Exponential\View\Extension\<Ext>\<Module>\<View>, in
extension/<ext>/classes/runnable/... (Commands, cronjob parts and module views as classes).
The generator maps them like any class.
Composer libraries
An extension that needs a library declares it in its own composer.json; the installation's Composer installs it into
vendor/. Do not ship vendor/ inside the extension (Composer packages and Packagist).
When a class is not found
| Symptom | Cause | Fix |
|---|---|---|
Class "expDemoList" not found | map not regenerated | ezpgenerateautoloads.php -e |
| Works under Apache, fails under Velocity | workers started before the class existed | exp:velocity restart |
| A setting names a class and the site breaks | the class was deployed after the setting | deploy code first; guard with class_exists() where a missing class must not break pages |
| The generator warns about a duplicate | two files declare the same class | rename one |
Related pages
- Anatomy of an extension
- Setting up a development environment
- Additional extension directories
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.