【发布时间】:2019-12-30 09:48:04
【问题描述】:
我有一个 Greeting.php
<?php
namespace sayinghello;
class Greeting {
public function getName() {
return "Hello!";
}
}
以及对 sayhello.php 的调用:
<?php
$greeting = new Greeting();
echo $greeting->getName();
当我尝试用浏览器打开 sayhello.php 时,会抛出 Class-Not-Found-Exception
('致命错误:未捕获错误:找不到类'sayinghello\Greeting' 在 C:\Users\User\IdeaProjects\EfP\src\sayinghello\sayinghello.php:2 堆栈跟踪:#0 {main} 抛出 C:\Users\User\IdeaProjects\EfP\src\sayinghello\sayinghello.php上线 2
我使用PHP和XAMPP-Stack,类似问题的解决方案没有解决问题...
【问题讨论】:
-
你包含那个文件了吗?
-
您是否将
Greeting.php包含在sayinghello.php中? -
是的,
include 'Greeting.php'; -
'Fatal error: .... on line 2的意思是,你还没有写include 'Greeting.php'; -
include_path的值是多少?你有没有修改它并且Greeting.php脚本与sayinghello.php在同一目录中?
标签: php