Lesson 7.3: Autoloads and activation
Two things stand between an extension's code and a working site: the kernel must find its classes, and the extension must be switched on. This lesson covers both: the autoload array and when to regenerate it, the two activation settings, the Extensions page of the administration, and what to do when a class is not found.
At a glance
| Course | Developers |
| Module | Module 7: Extensions |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Intermediate |
| Audience | Developers and administrators |
| Prerequisites | Lesson 7.2 |
Learning objectives
After this lesson, learners can:
- regenerate the extension autoloads with
php bin/php/ezpgenerateautoloads.php -eand say when it is needed; - find a class in the generated autoload array;
- switch an extension on with
ActiveExtensions[]or for one siteaccess withActiveAccessExtensions[]; - activate, deactivate and review changes in Setup > Extensions;
- diagnose a "class not found" with the autoloads,
checkclasses.phpand the caches.
Trainer's notes
How to present it
Sources: Extensions: find, install, configure, build and release,
The Extensions page and RAD tools
(the health check and checkclasses.php).
- Autoloads (4 minutes). The kernel does not search folders for classes at run time; it reads generated maps
in
autoload/.php bin/php/ezpgenerateautoloads.php -escans the extensions;-kthe kernel;-othe kernel overrides. Run-eafter adding, renaming or moving a class in an extension. - Activation (3 minutes).
site.ini [ExtensionSettings] ActiveExtensions[]insettings/override/switches an extension on everywhere;ActiveAccessExtensions[]in a siteaccess's settings switches it on for that siteaccess. - The Extensions page (5 minutes). Setup > Extensions: one list in loading order, Activate and
Deactivate buttons on the cards, Review changes shows the plan and the risks before anything is written,
and Regenerate autoload arrays does the
-erun from the browser. - When a class is not found (3 minutes). In order: is the file in
classes/(or another folder the generator scans)? did-erun? is the extension active? were the caches cleared and, on a server that keeps PHP in memory, the workers reloaded (lesson 13.2)?php bin/php/checkclasses.phplists every declared class PHP refuses to load.
Common questions
Do I commit the autoload files? The extension autoload array is generated per installation; your extension's repository holds the classes, not the generated map.
Why does a deactivated extension still show in the autoloads? The generator maps classes of extensions on disk; activation decides whether settings, designs and modules are used.
Can activation break a site? Yes, an extension with errors can stop every page. Activate on the development installation first; Review changes warns about known risks.
Pitfalls
- Forgetting
-eafter a new class. The most common cause of "class not found". - A class name used twice. Two extensions with the same class name: only one of them can be loaded; give yours your own prefix.
- Activating on the live site first. Always on development, then deploy.
Hands-on exercise
On the development installation.
Regenerate the extension autoloads:
php bin/php/ezpgenerateautoloads.php -e.Find your fetch function class in the generated map:
grep -rn "mysiteHelloFunctionCollection" autoload/.Rename the class file
classes/mysitehellofunctioncollection.phptoclasses/mysite_fetch.php, reload the playground of lesson 5.4 without regenerating, and read the error. Regenerate with-eand run again.Check that every class of the installation loads:
php bin/php/checkclasses.php --quiet-ok.Open Setup > Extensions in the administration and find the card of
mysite_hello. Read where it loads.Press Deactivate on
mysite_hello, then Review changes, read the plan, and leave without applying (or discard the changes).Make
mysite_helloactive for your public siteaccess only, with the console (and back again):php bin/php/console exp:ini add site.ini/ExtensionSettings/ActiveAccessExtensions mysite_hello siteaccess:<sa> --dry-runRead the dry run; do not run it without
--dry-rununless your trainer asks.Commit the renamed class file in the extension's repository.
Expected result
- Step 2: one line mapping the class to its file under
extension/mysite_hello/classes/. - Step 3: before regenerating, the fetch fails (the debug output names the missing class); after
-eit works. - Step 4 prints nothing when every class loads.
- Step 6: the review lists the deactivation of
mysite_helloand what depends on it. - The trainer asks each learner for the four checks of "class not found".
Quiz
- Which option of
ezpgenerateautoloads.phpscans the extensions? A.-kB.-oC.-eD.--all - Where is the setting that activates an extension for the whole installation?
- What does Review changes on the Extensions page do?
- Name the four checks when a class of your extension is not found.
- Which script lists every declared class PHP refuses to load?
Answers
- C.
-e. site.ini [ExtensionSettings] ActiveExtensions[], insettings/override/site.ini.append.php.- It shows what would change, with the risks, before anything is written.
- The file is in a scanned folder;
-eran; the extension is active; the caches were cleared and the PHP workers reloaded. php bin/php/checkclasses.php.
Further reading
- The Extensions page: activation, order, review and apply.
- Autoloads and class naming.
- Additional extension directories.
Related pages
- Module 7: Extensions
- Developers: course overview
- Trainers: start here
- 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.