【发布时间】:2012-02-23 00:23:13
【问题描述】:
编辑:添加了 PDO 调用。
这是实际的错误:
Notice: Object of class PDOStatement could not be converted to int in Unknown on line 0
我一般如何找出错误/通知的正确行,因为它不是 line 0?
我尝试使用 register_tick_function 回显 file:line,但不起作用,因为通知总是在我的总输出结束时输出。
我正在寻找一种通用的调试方法,因为我在我的那个对象的类中找不到任何错误。
// PHP PDO Standard
$db_server = 'mysql:host='.$this->db_host.';dbname='.$this->db_dbase;
try {
$this->db_connection = new PDO($db_server, $this->db_user, $this->db_pass);
$pdo_set = $this->db_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$pdo_set = $this->db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo_set = $this->db_connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
//DebugPrint($pdo_set, '$pdo_set');
} catch (PDOException $e) {
//print 'Error!: '.$e->getMessage().'<br/>';
die();
}
【问题讨论】:
-
检查你的 php.ini 中的 auto_prepend_file
-
只需查找将某些内容转换为 int 的行。在 PHP 中调试是一团糟。
-
您可以在服务器上安装 xdebug,例如netbeans 作为前端。见docs.php.net/debugger-about和netbeans.org/kb/docs/php/debugging.html
-
您是否在代码中的任何地方使用了 eval()、create_function() 或闭包或类似的东西?
-
你确实需要断点。然后单步执行您的代码,直到出现通知。所以你可以隔离/缩小来源。
标签: php