我有两个文件,第一个是test.php的,看起来像这样:PHP类,但进口
<?php
namespace My\Namespaces\Test;
class Test {
const ALERT_EMAIL = "AlertEmail";
const ALERT_SMS = "AlertSms";
const ALERT_NOTIFICATION = "AlertNotification";
} // class - EnumAlertType
?>
和其他文件尽量使用常量从test.php的
<?php
use My\Namespaces\Test;
$a = Test::ALERT_SMS;
?>
但我仍然得到Class 'My\Namespaces\Test' not found
错误,我不确定是否正确使用名称空间。谢谢
我认为这是一个打字错误,而在第二个例子中('Namespace' vs'Namespaces'),对吧?无论如何,你有没有配置自动加载(因为我没有看到你的代码中包含任何手动提及)? – Rangad
也许你会'include()'这个文件,而不是'使用'这个类。 – D4V1D
[Autoload classes from different folders]可能的重复(http://stackoverflow.com/questions/5280347/autoload-classes-from-different-folders) – D4V1D