【发布时间】:2013-07-22 05:03:29
【问题描述】:
以下是我从 PHP 文件中注意到的代码:
<?php
# Should log to the same directory as this file
$log = KLogger::instance(dirname(__FILE__), KLogger::DEBUG);
$args1 = array('a' => array('b' => 'c'), 'd');
$args2 = NULL;
$log->logInfo('Info Test');
$log->logNotice('Notice Test');
$log->logWarn('Warn Test');
$log->logError('Error Test');
$log->logFatal('Fatal Test');
$log->logAlert('Alert Test');
$log->logCrit('Crit test');
$log->logEmerg('Emerg Test');
$log->logInfo('Testing passing an array or object', $args1);
$log->logWarn('Testing passing a NULL value', $args2);
您会注意到 PHP 结束标记 (?>) 不存在,但代码中的所有语句仍然运行良好。我不明白如何在没有完成 PHP 标记 (?>) 的情况下执行代码。我进行了研究,但没有得到任何令人满意的解释。任何人都可以在这方面指导我吗?提前致谢。
【问题讨论】:
-
This 会帮助你
-
毫无疑问,我所做的研究比你少,所以如果以下内容听起来很愚蠢或侮辱性,请原谅我。由于该文件中只有 php 内容 - 即没有 html,我看不出在仍然有一个打开的 php 标签的情况下确定输入是否完成(在本例中为 php 文件)会有什么困难,然后只需在输入的末尾附加一个结束标记。
-
来自 - php.net/manual/en/language.basic-syntax.phptags.php -
If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.
标签: php