duanchu9914 2012-08-16 18:31
浏览 55
已采纳

为什么Doctrine 2的自动加载器在抛出异常时会尝试获取Exception实体?

This is the relevant code:

throw new Exception("Message");

And this is the error message I get:

Fatal error: require() [function.require]: Failed opening required 'C:\wamp\www\drupal-7.15\sites\all\modules\dbManip\Entities\Exception.php' (include_path='.;C:\wamp\bin\php\php5.3.13\pear\') in C:\wamp\bin\php\php5.3.13\pear\Doctrine\Common\ClassLoader.php on line 163

I believe Doctrine is trying to load the Exception class definition as if it were just another entity of mine, but as far as I know, Exception is native to PHP (I'm using PHP 5.3.13). My theory is that I did something wrong concerning the autoloader, but I'm not sure what. Here is what I have concerning the autoloader:

use Doctrine\ORM\Tools\Setup;

require_once("Doctrine/ORM/Tools/Setup.php");
Setup::registerAutoloadPEAR();

$classloader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classloader->register();

What am I doing wrong here? How can use throw an exception without doctrine's autoloader trying to load the Exception entity?

  • 写回答

1条回答 默认 最新

  • dongzhuzhou4504 2012-08-16 18:37
    关注

    This is PHP at play. Not Doctrine.

    When you declare your file in a namespace, it will use the same namespace for all classes mentioned in the file. To indicate the Exception class is from the root namespace, you must make it explicit.

    throw new \Exception("Message");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C