本文介绍了为什么即使正确声明了名称空间后仍会出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的文件夹结构
这是我的composer.json
代码
{
"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\\": "/"
}
}
}
使用此代码,我已经在供应商文件夹中成功生成了autoload.php文件.
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
在快照所示的非常根目录中,我有一个名为index.php的文件,代码如下:
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();
?>
运行此代码后,我得到了这样的错误
我不知道我在Google&上搜索解决方案的错误是什么从最近几个小时开始做各种事情.任何帮助将不胜感激.
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.) 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 :)
这篇关于为什么即使正确声明了名称空间后仍会出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!