【问题标题】:Notice: ... Unknown on line 0 - How to find correct line, it's NOT "line 0"注意:......第 0 行未知 - 如何找到正确的行,它不是“第 0 行”
【发布时间】: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-aboutnetbeans.org/kb/docs/php/debugging.html
  • 您是否在代码中的任何地方使用了 eval()、create_function() 或闭包或类似的东西?
  • 你确实需要断点。然后单步执行您的代码,直到出现通知。所以你可以隔离/缩小来源。

标签: php


【解决方案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;

return $sql_result 正在抛出此通知:

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

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

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

【讨论】:

  • 不过,这并不能回答您关于如何找到这些地方的原始问题。我什至不知道文件——它是“未知”...:\
【解决方案2】:

我暂时遇到了这个问题,并通过重新启动 (w)AMP 解决了这个问题。

我唯一的猜测是扩展没有正确加载。

就我而言,我得到:

MongoDB\Model\BSONDocument::getiterator in Unknown on line 0

【讨论】:

    猜你喜欢
    • 2016-09-24
    • 1970-01-01
    • 2020-03-18
    • 2015-12-15
    • 2019-01-28
    • 2016-12-13
    • 1970-01-01
    • 2015-07-21
    相关资源
    最近更新 更多