KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When I was digging into the source of a Composer package on github I noticed that there were php files that matched namespace names but were preceded with an underscore. Puzzled I pulled the package down (via Composer) and noticed that the class loader that Composer generates require d these underscored files explicitly, not autoloading as I'd expected. For instance, in the crunch/regular-expression package there is a namespace called Crunch\RegularExpression : -- src ---- Crunch ------- RegularExpression <-- folder containing classes ------- _RegularExpression.php <-- file namespace to Crunch/RegularExpression containing functions and constants (instead of a class) Initially I thought these underscored files were a feature of PSR-0 that I had missed, but then I looked at the Composer generated autoload_real.php and saw that _RegularExpression.php (amongst others) was being required explicitly: … $loader->register(true); require $baseDir . '/src/Crunch/_RegularExpression.php'; require $baseDir . '/src/Crunch/RegularExpression/_Modifier.php'; require $baseDir . '/src/Crunch/RegularExpression/Pattern/_Modifier.php'; require $baseDir . '/src/Crunch/RegularExpression/Pattern/_Assertion.php'; return $loader; … Haven't been able to find any meaningful documentation about this feature of Composer. Is it a good "standard" for exporting non-class based namespaced dependencies, like functions and constants? Update My question turned out to be a slight misnomer. The selected answer lead me to discover that non-class based assets can be explicitly declared for loading in composer.json : "autoload": { &q
Tags (comma-separated)
Save Edits
Cancel