我收到这个错误...
致命错误:未捕获的错误:在 /Applications/MAMP/htdocs/php-framework/index.php:21 中找不到类“TestApp\HelloWorld”堆栈跟踪:在 /Applications/MAMP/htdocs/php- 中抛出 #0 {main}第 21 行的 framework/index.php
我的猜测是 composer.json 没有连接到 src 文件夹,但不确定是什么原因造成的。我正在使用 PHP 7.3.1
这是我的文件:
索引.php
declare(strict_types = 1);
require_once __DIR__ . '/vendor/autoload.php';
$helloWorld = new TestApp\HelloWorld();
$helloWorld->announce();
自动加载.php
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInita3c559aaa188cb577ee6600701c362e7::getLoader();
你好世界.php
declare(strict_types = 1);
namespace TestApp;
class HelloWorld
{
public function announce(): void
{
echo 'Hello World!';
}
}
作曲家.json
{
"name": "philginsburg/php-framework",
"description": "An example of a modern PHP application.",
"type": "project",
"require": {},
"autoload": {
"psr-4": {
"TestApp\\": "src/"
}
}
}
致命错误:未捕获的错误:在 /Applications/MAMP/htdocs/php-framework/index.php:21 中找不到类“TestApp\HelloWorld”堆栈跟踪:在 /Applications/MAMP/htdocs/php- 中抛出 #0 {main}第 21 行的 framework/index.php