Reputation: 2734
I am pulling my hairs out on this one, and that does not happen frequently.
I am trying to use composers autoloader, with a directory of mine. The autoloader works perfectly with another directory.
I am using the following filestructure
-Root
| application
| Module
| Users
| Users.php
The Users.php contains the following code
<?php
namespace Module\Users;
class Users {
public function test() { return "Testing hippie-yaay!"; }
}
The composer.json contains the following psr-0 autoload
"psr-0":{"Module\\": "application/"}
which in the autoloader_namespaces.php compiles to the following
'Module\\' => array($baseDir . '/application'),
Which then again, is totally correct (Ive tested this by echoing out the basedir -application string. It is totally correct.
now. In my main class i do the following
<?php
namespace System\Core;
use Module\Users\Users;
class Initiater {
public function bootSystem() {
$u = new Users();
}
}
(this is basically what i do, ofcourse the other psr-0 autoloads i were talking about at the top are over this one, working just fine.)
I then get the following error.
Fatal error: Class 'Module\Users\Users' not found in
FYI: I tried with just "use Module\Users;"
and "new \Module\Users\Users();"
both returning the same error.
I hope one of you knows whats going on here. Best regards. Jonas
Upvotes: 3
Views: 6457
Reputation: 326
If anyone is still having this problem: after digging into ClassLoader.php
's findFileWithExtension()
, I found out that for me it was a case issue, like Sven mentioned. The class was named like AbcTest
, while the file name was ABCTest.php
. More generally, make sure that the file name matches the class name, case and all; it's just that case errors can be trickier to spot.
Upvotes: 1
Reputation: 2603
I had the same issue. I did a "composer update" and it fixed my issue. For some reason I had a namespace mismatch in the autoload_classmap.php
'Module' => $baseDir . '/application/Module/Users/Users.php',
and it was missing some info about the key part:
'Module\\Users' => $baseDir . '/application/Module/Users/Users.php',
So, like other mentioned, it's probably due to some invalid data that doesn't match your code.
Sometime you make a modification (like fixing a typo) and forgot to regenerate the autoloader and everything seems nice.
Upvotes: 2