I have been beating my head for a couple hours trying to figure out why the autoload is not working for "Authentication\auth()". The "dBase\db()" class is loading just fine, but i'm getting:
Error: Class 'Authentication\auth' not found in /var/htdocs/dev/test.php on line 8
when calling test.php.
Root composer.json -
"require": {
"geeshoe/dbClass": "dev-develop",
"geeshoe/authClass": "dev-master"
},
"autoload": {
"psr-4": {
"dBase\\": "vendor/geeshoe/dbclass/",
"Authentication\\": "vendor/geeshoe/authClass/"
}
}
authClass.php header -
<?php
namespace Authentication;
use dBase\db;
class auth extends db
{
test.php -
if (file_exists("vendor/autoload.php")) {
require "vendor/autoload.php";
} else {
echo "Dam.. Something went wrong!";
}
$test = new \dBase\db();
$var = new \Authentication\auth();
If someone could point out the obvious to me, that would be great. On a side note, autoload is not specified in the authClass->composer.json file for testing purposes.
The problem here is that in fact you don't use PSR-4. In PSR-4 class name should match file name. For db
class its fine because db class is located in db.php
file, but auth
class is located in authClass.php
file and that's the problem. You should update file name to auth.php
You might need to run:
composer dump-autoload
Also keep in mind in real packages, one vendor package has one namespace, so you don't create multiple namespaces for single package but only single
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With