I have the following directory structure (only the important files shown):
app/
- Http/
- Controllers/
- MyController.php // namespace App\Http\Controllers
- Utils/
- InternalUtils/
- Utility1.php // namespace App\Utils\InternalUtils
- Utility2.php // namespace App\Utils\InternalUtils
- ...
- MyUtility.php // namespace App\Utils
I am following the standard PSR-4 namespacing available in Laravel 5.
In the MyUtility.php file I am trying to use the following:
use InternalUtils\Utility1;
use InternalUtils\Utility2;
(new Utility1); // works
$className = 'Utility1';
(new $className); // throws Class 'Utility1' not found
Note that each Utility file is namespaced and contains a class name with the same name as Utility1.
The dynamic generation of objects is failing. Any ideas on what could be the issue?
use InternalUtils\Utility1;you have to useApp\Utils\InternalUtils\Utility1;