Problems with PHP namespaces and built-in classes, how to fix?

前端 未结 3 1209
后悔当初
后悔当初 2020-12-01 15:59

I\'m writing a small library in PHP and i\'m having some problems with built-in classes not being read. For example:

namespace Woody;

class Test {
  public          


        
3条回答
  •  时光说笑
    2020-12-01 16:34

    This:

    namespace Woody;
    use PDO;
    

    Or:

    $db = new \PDO(params);
    

    Point in case is, that the class PDO is not a full qualified name within your Namespace, so PHP would look for Woody\PDO which is not available.

    See Name resolution rulesDocs for a detailed description how class names are resolved to a Fully qualified name.

提交回复
热议问题