2012-02-23 39 views
0
 I am studying namespace in php and **Doctrine 2.2** for a week. 
I explorered several blogs and read several articles about namespace in php. 
    And i understand that, when we want to use different namepaces in different php pages, 
we must write: include('php page that belong namespace we want to use'); 

    But Doctrine 2.2 doesn't use any include or require or require_once 
statements for using namespace. Almost all script in **Doctrine 2.2** like that : 

/*i am at Doctrine\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 
    ............. 
    .................................. 
    .................................. 
    .................................. 
    .................................. 
?>** 
    There isn't any include or require statement in **Doctrine 2.2**. 
But we run the page (Doctrine\ORM\EntityManager.php) appear fatal error, 

致命错误: 接口 '学说\共同\持久性\的ObjectManager' 未找到用C :\ XAMPP \ htdocs中\ WWW \ DoctrineExplained \ DoctrineORM \学说\ ORM \ EntityManager.php第45行上为什么教条2.2使用-namespace-和-use-而没有任何include或require声明..?

Although **Doctrine 2.2** is stable version of **Doctrine ORM**, 
why doesn't use include or require for --namespaces-- and --uses--? 

回答

1

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

这也可以做很长时间。在这些约定被修改和命名空间推动这一改变之前,这需要时间。

+0

我想,你想表达对名称空间语句和约定的改变。不是吗?请告诉我更多。 – 2012-02-24 00:54:46

+0

你想知道什么?不得不上课一直很乏味。它导致大量的包含需要加载太多代码并增加内存占用量。自动加载被引入来解决这个问题。 – 2012-02-24 01:43:43

+0

再次感谢您的回复。我只是想知道为什么Doctrine ORM不会在每个页面中使用include或require。现在你解释了原因。我以前认为,(USE)声明像包含或要求一样工作。下一个可能吗? – 2012-02-24 13:37:13

相关问题