#29648 [NEW]: cant throw exceptions with __autoload (to catch and handle them - workaround?)

From: Date: Fri, 13 Aug 2004 10:30:21 +0000
Subject: #29648 [NEW]: cant throw exceptions with __autoload (to catch and handle them - workaround?)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-64536@lists.php.net to get a copy of this message
From: black at scene-si dot org Operating system: debian PHP version: 5.0.0 PHP Bug Type: Scripting Engine problem Bug description: cant throw exceptions with __autoload (to catch and handle them - workaround?) Description: ------------ I've tried to create an __autoload() function which would throw an exception if it can't load the class name from a file depending on the classname i request with the php code. I couldnt catch the exception with a try/catch clause, because it always failed (see expected/actual result below). My workaround was to add this after the first include_once statement inside the __autoload: if (!class_exists($classname)) { eval("class ".$classname." { }"); } Afterwards instead of a try/catch clause i used a method_exist call to see if a general function was defined (one that i require to have). Reproduce code: --------------- <?php function __autoload($classname) { if (substr($classname,0,7)=="object_") { @include_once("include/object.".substr($classname,7).".php"); return; } @include_once("class.".$classname.".php"); } try { $object = new object_wtf("hello"); } catch (Exception $e) { echo "__autoload failed "; var_dump($object); } Expected result: ---------------- Output: __autoload failed NULL Actual result: -------------- Fatal error: Class 'object_wtf' not found in /root/monotek/mono/commands/test.php on line 15 -- Edit bug report at http://bugs.php.net/?id=29648&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29648&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29648&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29648&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29648&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29648&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29648&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29648&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29648&r=support Expected behavior: http://bugs.php.net/fix.php?id=29648&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29648&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29648&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29648&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29648&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29648&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29648&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29648&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29648&r=float

« previous php.bugs (#64536) next »