"fixed CreateObject to not suppress the error, if it cant find a class file or there are eg. syntax errors in it

--> now you can find the error in the error_log and dont get only a blank page
(also optimized it so far, that we first try to autoload the class and use the diverse \"magic\" only if that fails)"
This commit is contained in:
Ralf Becker 2009-03-13 12:47:53 +00:00
parent df134f3588
commit efb3189b49

View File

@ -675,7 +675,9 @@ function &CreateObject($class)
{ {
list($appname,$classname) = explode('.',$class); list($appname,$classname) = explode('.',$class);
if (!@include_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php')) if (!class_exists($classname))
{
if (!file_exists(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'))
{ {
static $replace = array( static $replace = array(
'datetime' => 'egw_datetime', 'datetime' => 'egw_datetime',
@ -692,11 +694,11 @@ function &CreateObject($class)
//throw new Exception(__METHOD__."('$class') old classname '$classname' used in menuaction=$_GET[menuaction]!"); //throw new Exception(__METHOD__."('$class') old classname '$classname' used in menuaction=$_GET[menuaction]!");
error_log(__METHOD__."('$class') old classname '$classname' used in menuaction=$_GET[menuaction]!"); error_log(__METHOD__."('$class') old classname '$classname' used in menuaction=$_GET[menuaction]!");
$classname = $replace[$classname]; $classname = $replace[$classname];
include_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php');
} }
} }
if (class_exists($classname)) // this will stop php with a 500, if the class does not exist or there are errors in it (syntax error go into the error_log)
{ require_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php');
}
$args = func_get_args(); $args = func_get_args();
switch(count($args)) switch(count($args))
{ {
@ -725,7 +727,6 @@ function &CreateObject($class)
eval($code); eval($code);
break; break;
} }
}
if (!is_object($obj)) if (!is_object($obj))
{ {
echo "<p>CreateObject('$class'): Cant instanciate class!!!<br />\n".function_backtrace(1)."</p>\n"; echo "<p>CreateObject('$class'): Cant instanciate class!!!<br />\n".function_backtrace(1)."</p>\n";