Skip to content
Daniel Wentsch

Things read, heard, watched and found. Now and then a thought of my own.

Timeline
Article

Autoloading & Namespaces in PHP

Jonathan Daggerhart

Read on daggerhartlab.com (opens in a new tab) 2 highlights · Sep 2023 – Jul 2024

What are namespaces and autoloading in PHP? This post explains the What, Why, and How of this fundamental OOP concept, along with PSR-4.

12 Sep 2023

PHP Standard Recommendation (PSR) 4 is a commonly used pattern for organizing a PHP project so that the namespace for a class matches the relative file path to the file of that class.

For example, if you are working within a project that makes use of PSR-4 and you are dealing with a namespaced class named \Jonathan\SomeBundle\Validator();, you can be sure that the file for that class can be found in this relative location in the file system: <relative root>/Jonathan/SomeBundle/Validator.php.

15 Jul 2024

The use keyword “imports” a given namespace into the current context, allowing you to make use of its contents without having to refer to its full path each time.