Re: [Pre-RFC][Discussion] Native Engine-Level PSR-4 Autoloader

From: Date: Thu, 16 Jul 2026 06:41:06 +0000
Subject: Re: [Pre-RFC][Discussion] Native Engine-Level PSR-4 Autoloader
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-131957@lists.php.net to get a copy of this message
On Thursday, 16 July 2026 06:25:34 CEST fennic log wrote: > PSR-4 has been the community standard for autoloading namespaced classes > since 2014 and is used by virtually every modern PHP package via > Composer. However, > the actual autoloading still requires userspace code: > spl_autoload_register() with a closure or class method (almost > always > generated by Composer) that performs prefix matching and > file_exists/require. > > This RFC proposes adding a small set of native functions that allow the > engine itself to perform PSR-4 autoloading directly from registered prefix > → base directory mappings. Package managers and applications can opt into > the faster, engine-native path instead of (or in addition to) registering a > userspace callback. > > With emphasis on PSR-4 compliance, the engine implementation MUST follow > the PSR-4 specification exactly for prefix matching, relative path > construction, file extension (.php), and case sensitivity of > the > terminating class name. > This can provide a performance improvement for PSR-4 heavy workloads by > eliminating userspace callback overhead. > > To fully support PSR-4 autoloading I would propose a function > spl_autoload_psr4_register and complimenting functions. I implemented a PECL extension doing pretty much this in https://github.com/ pprkut/autoload-psr, minus the complimenting functions. I can't speak for performance benefits as I didn't do any benchmarks, I don't think they'd be very noticeable though. My primary motivation for writing it was to have an autoloader available from script start. The extension supports PSR-0 as well, which fits even better (IMHO) with that workflow since it means truly zero setup compared to PSR-4. Anyway, perhaps have a look. At the very least it might serve as reference point. Grs, Heinz

« previous php.internals (#131957) next »