Reputation: 4710
My ./app
folder looks like:
+-- app
+-- Classes
+-- Events
+-- EventBase.php
+-- EventX.php
There's nothing secret with EventX
file:
<?
namespace App\Classes\Events;
class EventX {
// ...
}
EventBase.php
represents a Facade that inside it I just try to instantiate an EventX
:
public function someMethod() {
new \App\Classes\Events\EventX;
// ...
}
After this line, Framework throw an exception telling that class was not found:
Symfony\Component\Debug\Exception\FatalThrowableError (E_ERROR)
Class 'App\Classes\Events\EventX' not found
Even that:
file_exists(__DIR__ . '\EventX.php'); // true
I already had this issue before when trying to create Facades and solved by moving class file from his current directory and after moving back (yeah, I don't why but it worked).
Something tells me that this is an issue of autoload process, so I tried these command (but still not working):
php artisan cache:clear
php artisan clear-compiled
php artisan config:clear
composer dump-autoload
What can I do in order to investigate the problem?
Upvotes: 2
Views: 2179
Reputation: 624
I think the problem is with the php tag <?
<?php
namespace App\Classes\Events;
class EventX {
// ...
}
PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).
Upvotes: 1
Reputation: 622
You need to add the new namespace to your composer.json to the key "psr-4"
"psr-4": {
"App\\": "app/",
"Classes\\": "app/classes/"
otherwise composer can't detect your new namespace
Another approach can be found here: https://stackoverflow.com/a/28360186/6111545
Upvotes: 0