PHP theorytheory 0/50 · 0%
Fundamentals · easy

16. Namespaces & Autoloading

Organizing code at scale.

Namespaces group related classes/functions and avoid name collisions, declared with namespace App\Models; at the top of a file. Fully qualified names use backslashes, e.g. \App\Models\User.

Composer's PSR-4 autoloading maps namespaces to directory structures so classes load automatically without manual require statements.

Check your understanding

  1. 1. What declares a namespace at the top of a file?

  2. 2. What standard maps namespaces to folder structure for autoloading?