有一系列我动态调用的函数是这样的:
$function = 'someFunction';
$x = $function();
Run Code Online (Sandbox Code Playgroud)
..但是,如果函数需要参数,并且我不在调用中对其进行编码,我似乎会崩溃页面.例如:
function someFunction( $in_param1 ) {
return "SUCCESS";
}
$function = 'someFunction';
// this next line does not work
$x = $function() or die("error");
Run Code Online (Sandbox Code Playgroud)
我该如何处理这种错误?
谢谢 -
您可以使用set_error_handler函数捕获它:
function handle_errors( $errno, $errstr )
{
die( "Your error will be caught here" );
}
set_error_handler( "handle_errors" );
$function = 'someFunction';
$x = $function();
Run Code Online (Sandbox Code Playgroud)