问题
This is my folder structure
This is my composer.json
code
{
"name": "hashstar/hashstar",
"description": "Online shopping",
"type": "project",
"license": "private",
"authors": [
{
"name": "Akshay Shrivastav",
"email": "akshayshrivastav866@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.5.0"
},
"autoload": {
"psr-4": {
"modules\\": "/"
}
}
}
With this code, i have successfully generated the autoload.php thing in the vendor folder.
I have a file name HelloWorld.php in modules folder
In the very root directory as the snapshot shows below i have an file named index.php the code is as follows:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use modules\HelloWorld\Greetings;
echo Greetings::sayHelloWorld();
?>
After running this codes I am getting the errors like this
I don't know what the error is I have been searching the solution on google & doing various things from last few hours. Any helps would be appreciated.
回答1:
Actually, i got the error I wasn't doing two things.
1.) Using vendor name folder structure with namespaces in it.
2.) I wasn't using dump-autoload thing. After doing these two things finally my code is working. Thanks for the help :)
来源:https://stackoverflow.com/questions/42179503/why-am-i-getting-error-even-after-declaring-namespaces-correctly