php是一个嵌套的缩写名称,是英文超级文本预处理语言,它的语法混合了C、Java、Perl以及php自创新的语法,主要用来做网站开发,许多小型网站都用php开发,因为php是开源的,从而使得php经久不衰。
使用lint检查
用lint静态检查。
静态是一种只检查语法描述方法而不执行程序的方法。
此时使用lint命令。
※php_check_syntax这个语法检查函数已经被废止,所以不能使用。
然后准备实际出现错误的php文件。
lint_test.php
它只是一个在屏幕上显示error的代码。
将lint_test.php移动到某个目录并发出以下命令。
php -l lint_test.php执行结果
PHP Parse error: syntax error, unexpected end of file, expecting ',' or ';' in lint_test.php on line 2 Parse error: syntax error, unexpected end of file, expecting ',' or ';' in lint_test.php on line 2Errors parsing lint_test.phpsyntax error=输出语法错误指示。
它还返回错误行数为line 2。
因为有unexpected end of file,是第2行没有“;”是原因。
那么,修改lint_test.php,再次执行lint命令。
执行结果为:
No syntax errors detected in lint_test.php
显示没有语法错误。
使用xdebug动态检查语法错误
首先,启用xdebug。
①从下面的官方站点下载xdebug,并记下下载的.dll文件所在的本地环境的路径。
https://xdebug.org/download.php
② 将以下内容添加到php.ini中。
zend_extension = ①中记录的路径②重启Web服务器(Apache等)
这样就完成了设置。
使用xdebug检查错误
我们运行上述使用的lint_test.php。
lint_test.php