【问题标题】:"PHP parse error" vs "Parse error" in OS X Server Terminal commandOS X 服务器终端命令中的“PHP 解析错误”与“解析错误”
【发布时间】:2011-08-27 11:10:30
【问题描述】:

我正在通过终端在 OS X 10.6 服务器上运行 PHP 脚本,如下所示:

cexa:~ soinro$ php /Volumes/dev1/cron/cron.php

如果脚本有错误,我会得到输出:

PHP Notice:  Use of undefined constant ccccc - assumed 'ccccc' in /Volumes/dev1/cron/cron.php on line 6
Notice: Use of undefined constant ccccc - assumed 'ccccc' in /Volumes/dev1/cron/cron.php on line 6
PHP Parse error:  syntax error, unexpected $end in /Volumes/dev1/http/~dev/_cron/cron.php on line 26
Parse error: syntax error, unexpected $end in /Volumes/dev1/http/~dev/_cron/cron.php on line 26

如您所见,每个通知/错误都会显示两次:一次是“PHP 解析错误”,一次是“解析错误”。

我调用的文件是/Volumes/dev1/cron/cron.php。如果此文件有错误,我只会收到“解析错误”,但如果 requires 的文件有错误,我会同时收到“PHP 解析错误”和“解析错误”消息。

为什么会发生这种情况,我该如何做到这一点,以便我始终收到两条消息(或只收到没有“PHP Parse 错误”的消息);

为了便于讨论,这里是我调用的原始代码:

ini_set('display_errors', 1);
$crons = array_merge(glob("/Volumes/dev1/http/*/_cron/*"), glob("/Volumes/dev1/http/~dev/*/_cron/*"));
foreach ($crons as $cron):
/* there is only one file in the array */
require_once $cron;
endforeach;
/* this is the endforeach I leave out when I want an error in this file */


这是require_once的文件

$mails = $db->result("select * from newsletter where status = 'sending'");
/* there are 3 elements in $mails */
foreach ($mails as $mail):
echo 'x';
endforeach;
/* this is the endforeach I leave out when I want an error in this file */


非常感谢!!

【问题讨论】:

  • 该文件设置了任何错误处理程序?
  • 代码如上。第一个文件的开头有一个ini_set('display_errors', 1); 行,没有别的。

标签: php macos terminal


【解决方案1】:

发生的情况是您同时启用了display_errorslog_errors

启用log_errors 时,PHP 会将错误写入由error_log ini 设置指定的文件中(不要与log_errors 混淆)。如果error_log 未设置,错误将写入标准输出,这就是您看到它们两次的原因。

您必须禁用 display_errors 和 log_errors 之一;或将 error_log 设置为某个文件名(如果您想记录到 syslog,则设置为 syslog)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 2017-09-08
    • 2014-04-14
    • 2020-01-31
    相关资源
    最近更新 更多