为什么条令2.2在没有任何include或require语句的情况下使用-namespace和-use


Why does doctrine 2.2 use -namespace- and -use- without any include or require statement?

我正在php和条令2.2中学习命名空间一周。

我浏览了几个博客,阅读了几篇关于php中命名空间的文章。

我知道,当我们想在不同的php页面中使用不同的名称空间时,我们必须写:include('php page that belong namespace we want to use');

但是条令2.2没有使用任何includerequirerequire_once语句来使用名称空间。条令2.2中的几乎所有脚本都是这样的:

条令''ORM''EntityManager.php

<?php
namespace Doctrine'ORM;
use Closure, Exception,
    Doctrine'Common'EventManager,
    Doctrine'Common'Persistence'ObjectManager,
    Doctrine'DBAL'Connection,
    Doctrine'DBAL'LockMode,
    Doctrine'ORM'Mapping'ClassMetadata,
    Doctrine'ORM'Mapping'ClassMetadataFactory,
    Doctrine'ORM'Query'ResultSetMapping,
    Doctrine'ORM'Proxy'ProxyFactory,
    Doctrine'ORM'Query'FilterCollection;
class EntityManager implements ObjectManager
{
    /**
     * The used Configuration.
     *
     * @var 'Doctrine'ORM'Configuration
    .............
    ..................................
    ..................................
    ..................................
    ..................................
?>

条令2.2中没有任何includerequire声明。

但我们运行的页面(Doctrine''ORM''EntityManager.php)出现致命错误,

致命错误:找不到接口"Doctrine''Common''Persistence''ObjectManager"在第45行上的C:''examplep''htdocs''www''DoctrineExplaine''Doctrine RM''Doctrinet''ORM''EntityManager.php中

尽管Doctrine 2.2Doctrine ORM的稳定版本,为什么不将includerequire用于命名空间和use

大多数PHP 5.3代码都是这样的。Doctrine希望在开始使用之前设置好自动加载。您可以定义自己的__autoload()函数,使用spl_register_autoload()或使用与许多框架捆绑在一起的实现之一。

这也可以持续很长一段时间。只是花了一段时间才对约定进行调整,并推动名称空间进行更改。