2012-02-07 132 views
1

我尝试使用命名空间时出现此错误。致命错误:未找到类'App PDO'

我已经

namespace App;

顶部,类看起来像

class database{ 

    function __construct(..) 
    try{ 
     $this->db = new PDO(...) <-- here the error 
    ... 
    } 
} 

我不知道”怎么办命名空间的工作?如果找不到app/PDO,不应该将PHP回退到默认的PDO类中?

回答

3

Shouldn't PHP fallback to the default PDO class if app/PDO is not found?

不,不应该。

documentation

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

+0

好的,那么“pdo”的完全限定名称是什么。我不知道任何其他...... – Alex 2012-02-07 14:27:57

+1

@Alex:'\ PDO'会为你工作。 – 2012-02-07 14:28:21

+0

好的谢谢,它现在的作品:) – Alex 2012-02-07 14:33:18

1

只需在名称空间之后和类之前添加use PDO;即可。

相关问题