Obviously, autoloading classes with absolute namespaced names (\One\Two\Three) that translate to actual directory paths (One/Two/Three.php) is rather simple.
However, I am curious if there is any way to autoload classes who have been instantiated (for the first time in the PHP process) using a namespaced name relative to the current namespace (loading Two\Three from \One, for example).
As “__autoload” executes in the global namespace and only accepts one parameter (the class name, including namespace components) I cannot see how it could know where to look for the class.
However, I assume some PHP wizard has found a solution to this, seeing as it would be very inconvenient to always specify classes by their absolute namespaced name.
Thanks in advance for any help!
You do always get the full namespace in your autoloader:
Output: