"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,56 +675,57 @@ 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))
{ {
static $replace = array( if (!file_exists(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'))
'datetime' => 'egw_datetime',
'uitimesheet' => 'timesheet_ui',
'uiinfolog' => 'infolog_ui',
'uiprojectmanager' => 'projectmanager_ui',
'uiprojectelements' => 'projectmanager_elements_ui',
'uiroles' => 'projectmanager_roles_ui',
'uimilestones' => 'projectmanager_milestones_ui',
'uipricelist' => 'projectmanager_pricelist_ui',
);
if (isset($replace[$classname]))
{ {
//throw new Exception(__METHOD__."('$class') old classname '$classname' used in menuaction=$_GET[menuaction]!"); static $replace = array(
error_log(__METHOD__."('$class') old classname '$classname' used in menuaction=$_GET[menuaction]!"); 'datetime' => 'egw_datetime',
$classname = $replace[$classname]; 'uitimesheet' => 'timesheet_ui',
include_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'); 'uiinfolog' => 'infolog_ui',
'uiprojectmanager' => 'projectmanager_ui',
'uiprojectelements' => 'projectmanager_elements_ui',
'uiroles' => 'projectmanager_roles_ui',
'uimilestones' => 'projectmanager_milestones_ui',
'uipricelist' => 'projectmanager_pricelist_ui',
);
if (isset($replace[$classname]))
{
//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]!");
$classname = $replace[$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');
} }
if (class_exists($classname)) $args = func_get_args();
switch(count($args))
{ {
$args = func_get_args(); case 1:
switch(count($args)) $obj =& new $classname;
{ break;
case 1: case 2:
$obj =& new $classname; $obj =& new $classname($args[1]);
break; break;
case 2: case 3:
$obj =& new $classname($args[1]); $obj =& new $classname($args[1],$args[2]);
break; break;
case 3: case 4:
$obj =& new $classname($args[1],$args[2]); $obj =& new $classname($args[1],$args[2],$args[3]);
break; break;
case 4: default:
$obj =& new $classname($args[1],$args[2],$args[3]); $code = '$obj =& new ' . $classname . '(';
break; foreach($args as $n => $arg)
default: {
$code = '$obj =& new ' . $classname . '('; if ($n)
foreach($args as $n => $arg)
{ {
if ($n) $code .= ($n > 1 ? ',' : '') . '$args[' . $n . ']';
{
$code .= ($n > 1 ? ',' : '') . '$args[' . $n . ']';
}
} }
$code .= ');'; }
eval($code); $code .= ');';
break; eval($code);
} break;
} }
if (!is_object($obj)) if (!is_object($obj))
{ {