doupijin0397
doupijin0397
2013-03-03 12:32

PHP`-l`标志没有找到错误

已采纳

Why might the PHP -l switch not find errors in test.html.

$ cat test.html 
<?php
error_reporting(E_ALL);
echo "Hello, world!";

sdfsdfsdfsdf

?>
$ php -dhtml_errors=0 -ddisplay_errors=On -l test.html 
No syntax errors detected in test.html
$ php test.html 
Hello, world!PHP Notice:  Use of undefined constant sdfsdfsdfsdf - assumed 'sdfsdfsdfsdf' in test.html on line 7
$ 

Other types of errors are also not found, such as undefined functions, require_once() to nonexistant files, incorrect syntax in array declarations, etc. Why might this be?

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doudiza9154 doudiza9154 8年前

    -l Syntax check only (lint)

    -l performs a static syntax check. The code is never actually executed. And in your code there are no syntax errors.

    The gibberish at the end of your file is considered a constant (since it's a valid name for a constant) and undefined constants evaluate to their string representation (and cause an E_NOTICE). Since it's the last statement in the file the missing semicolon also does not result in a syntax error.

    Since PHP is a dynamic language an undefined constant cannot be detected without executing the code - define() is just a normal function after all.

    点赞 评论 复制链接分享
  • dq05304 dq05304 8年前

    These are not syntax error, these are runtime errors. -l only lints the file.

    点赞 评论 复制链接分享

为你推荐