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?
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");