致命错误:找不到"App \ PDO"类 [英] Fatal error: Class 'App\PDO' not found in
本文介绍了致命错误:找不到"App \ PDO"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用名称空间时出现此错误.
I get this error when I try to use namespaces.
我有
namespace App;
顶部,班级看起来像
class database{
function __construct(..)
try{
$this->db = new PDO(...) <-- here the error
...
}
}
我不了解名称空间如何工作?如果未找到app/PDO,PHP是否应该回退到默认的PDO类?
I dont' understand how do namespaces work? Shouldn't PHP fallback to the default PDO class if app/PDO is not found?
推荐答案
如果找不到app/PDO,PHP是否应该回退到默认的PDO类?
Shouldn't PHP fallback to the default PDO class if app/PDO is not found?
不,不应该.
从文档:
类名称始终解析为当前名称空间名称.因此,要访问内部或非命名空间的用户类,一个人必须使用其完全限定的名称来引用它们
对于您的特定示例,PDO
的完全限定名称为\PDO
.
For your specific example, the fully qualified name for PDO
would be \PDO
.
这篇关于致命错误:找不到"App \ PDO"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文