我嘗試使用命名空間時出現此錯誤。致命錯誤:未找到類'App PDO'
我已經
namespace App;
頂部,類看起來像
class database{
function __construct(..)
try{
$this->db = new PDO(...) <-- here the error
...
}
}
我不知道」怎麼辦命名空間的工作?如果找不到app/PDO,不應該將PHP回退到默認的PDO類中?
我嘗試使用命名空間時出現此錯誤。致命錯誤:未找到類'App PDO'
我已經
namespace App;
頂部,類看起來像
class database{
function __construct(..)
try{
$this->db = new PDO(...) <-- here the error
...
}
}
我不知道」怎麼辦命名空間的工作?如果找不到app/PDO,不應該將PHP回退到默認的PDO類中?
Shouldn't PHP fallback to the default PDO class if app/PDO is not found?
不,不應該。
Class names always resolve to the current namespace name. Thus to access internal or non-namespaced user classes, One must refer to them with their fully qualified Name
爲了您的具體示例,PDO
完全合格的名稱將是\PDO
。
只需在名稱空間之後和類之前添加use PDO;
即可。
好的,那麼「pdo」的完全限定名稱是什麼。我不知道任何其他...... – Alex 2012-02-07 14:27:57
@Alex:'\ PDO'會爲你工作。 – 2012-02-07 14:28:21
好的謝謝,它現在的作品:) – Alex 2012-02-07 14:33:18