注意:...第0行未知 - 如何找到正确的行,它不是"行0"

djo*_*jot 6 php

编辑:添加了PDO调用.

这是实际错误:

Notice: Object of class PDOStatement could not be converted to int in Unknown on line 0
Run Code Online (Sandbox Code Playgroud)

我怎么能一般找出哪一行是错误/通知的正确行,因为它不是 line 0

我尝试使用register_tick_function echoing out 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();
}
Run Code Online (Sandbox Code Playgroud)

djo*_*jot 1

最后,我找到了自己的问题的答案:

// doing PDO-sql, inserting session data, I ran into my problem.
$this->db_connection = new PDO(...);
$sql_query = "INSERT INTO ".$this->session_db_table." (...) VALUES (...)";
$sql_result = $this->db_connection->query($sql_query);

// This is the line (ideally named "0") from the notice:
return $sql_result;
Run Code Online (Sandbox Code Playgroud)

return $sql_result正在抛出这个通知:

“注意:第 0 行 Unknown 中的 PDOStatement 类对象无法转换为 int”

$sql_result是一个object; 预期的返回格式似乎是boolean.

所以我删除了这个return,通知现在消失了。