【发布时间】: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);行,没有别的。