Skip to content

Instantly share code, notes, and snippets.

<?php
// This code is what the Symfony Dependency Injection container performs
// under the hood when registering a listener.
$eventDispatcher->addListener(
KernelEvents::REQUEST,
function ($event) {
// only when here, MyListener and ExpensiveDependency trigger autoloading
// and the time of calling their constructor is spent.
(new MyListener(new ExpensiveDependency))->onKernelRequest($event);
},
<?php
require_once 'vendor/autoload.php';
$functions = spl_autoload_functions();
foreach ($functions as $function) {
if ($function instanceof \Closure) {
$reflection = new ReflectionFunction($function);
// check if autoloader closure is from laminas zendframework bridge
if (str_contains($reflection->getFileName(), 'laminas-zendframework-bridge')) {