> per the manual, exceptions thrown in an autoload method are swallowed,
> and an E_ERROR is triggered by php.
>
> http://us2.php.net/manual/en/language.oop5.autoload.php

I have read that note before, and wondered exactly what it was referring to 
since you can throw exceptions within an autoloader and catch them (or have 
your exception handler do whatever it needs to do with them).

<?php

   function autoloader($className)
   {
      echo "autoloading" . PHP_EOL;
      throw new Exception("Fail");
   }

   spl_autoload_register("autoloader");

   try
   {
      // Exception
      $obj = new NonExistentClass;
   }
   catch(Exception $e)
   {
      echo "caught" . PHP_EOL;
   }

   try
   {
      // Exception
      $const = constant("NonExistentClass::NON_EXISTENT_CONSTANT");
   }
   catch(Exception $e)
   {
      echo "caught" . PHP_EOL;
   }

   try
   {
      // Fatal error
      $const = NonExistentClass::NON_EXISTENT_CONSTANT;
   }
   catch(Exception $e)
   {
      echo "never happens" . PHP_EOL;
   }
?>

Will output:

autoloading
caught
autoloading
caught
autoloading
PHP Fatal error: Undefined class constant


I would expect accessing a constant directly to behave as constant() does at 
the moment .... and I would expect constant() to behave as the manual says it 
does (and return NULL for non existent class constants instead of throwing 
E_ERRORs).


Ben Bidner

+61.7.3161.2000 (office) | +61.7.3009.0651 (fax) | +61.4.3201.5362 (mobile)
http://www.vuetec.com/


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to