我有一个用于处理 SQL 的通用函数。我收到了这个错误(一天只有几次,不经常)。
PHP Catchable fatal error: Object of class PDO could not be converted to string in...
基本上,为我正在使用的函数传递了一个值数组,我必须在我的代码中滑倒并在该数组中放置了一个 PDO 对象。
我需要创建一个 array_filter 函数来检查变量是否是 PDO 对象。我该如何为此做一个简单的 if 语句?
if($var == PDO)
编辑:感谢您的精彩回答!如果有人感兴趣,这就是我解决问题的方法。我能够找到无效输入的来源。
$before=$original_array;
$after = array_filter($before, "find_error");
if(count($before)!=count($after)){
$error=print_r(debug_backtrace(false),true);
$arr=print_r($before,true);
send_message("admin@email.com","Error Report",$arr.$error);
//send_message is a simple function for sending emails. You could also write information to a txt file, etc.
}
function find_error($var){
return !($var instanceof PDO);
}