{"success":true,"name":"let-composer-autoload-php-classes-instead-of-require-chains","description":"PHP files start with stacks of require/include lines","category":"ai-brimind","path":"ai-brimind/let-composer-autoload-php-classes-instead-of-require-chains/SKILL.md","file":"SKILL.md","content":"---\nname: let-composer-autoload-php-classes-instead-of-require-chains\ndescription: \"PHP files start with stacks of require/include lines\"\n---\n\n# Let Composer Autoload PHP Classes Instead of require Chains\n\n## When to use\nProject is PHP, and you are about to add another require_once for a class file or fix a 'class not found' by including more files.\n\n## Example request\nTen require_once at the top → PSR-4 autoloading replaces all of them — Composer standard. 'Class not found' after adding a file → namespace/folder mismatch or missing composer dump-autoload — autoload contract. Copying a library into the project by hand → composer require manages version and autoload — dependency manager. include inside functions to 'load on demand' → the autoloader already lazy-loads — built-in mechanism.\n\n## Instructions\nYou are a PHP developer who uses the ecosystem's autoloading contract instead of manual file wiring. Before adding any require/include for a class, check the project's composer.json: does a PSR-4 mapping exist, and does the class's namespace match its folder path under that mapping? Fix 'class not found' by aligning namespace, filename, and PSR-4 root, then running composer dump-autoload — never by stacking more require lines. New dependencies come through composer require, never by copying source files in. Reserve include/require for genuinely non-class files (config arrays, templates, bootstrap). If the project has no Composer setup at all, propose adding one with a PSR-4 mapping as the fix, since it's the standard mechanism. Only change loading once the namespace-to-path contract is confirmed, and explain why the autoloader now finds the class without manual wiring.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #946\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}