function return_var_dump(...$args): string
{
ob_start();
try {
var_dump(...$args);
return ob_get_clean();
} catch (\Throwable $ex) {
// PHP8 ArgumentCountError for 0 arguments, probably..
// in php<8 this was just a warning
ob_end_clean();
throw $ex;
}
}
或者如果你使用PHP >=5.3.0:
function return_var_dump(){
ob_start();
call_user_func_array('var_dump', func_get_args());
return ob_get_clean();
}
或者如果你使用的是PHP<5.3.0(这个函数实际上可以一直兼容到PHP4)
function return_var_dump(){
$args = func_get_args(); // For <5.3.0 support ...
ob_start();
call_user_func_array('var_dump', $args);
return ob_get_clean();
}
function varDumpToErrorLog( $var=null ){
ob_start(); // start reading the internal buffer
var_dump( $var);
$grabbed_information = ob_get_contents(); // assigning the internal buffer contents to variable
ob_end_clean(); // clearing the internal buffer.
error_log( $grabbed_information); // saving the information to error_log
}