Rumah >php教程 >php手册 >vim(gvim)配合ZendCodeAnalyzer检查php语法

vim(gvim)配合ZendCodeAnalyzer检查php语法

WBOY
WBOYasal
2016-06-06 19:54:061581semak imbas

http://www.vimer.cn/2011/01/vimgvim%E9%85%8D%E5%90%88zendcodeanalyzer%E6%A3%80%E6%9F%A5php%E8%AF%AD%E6%B3%95.html 本博之前有写过一篇vimphp.exe检查php语法的文章-在vim中检查php语法式,这种方式的优点是只依赖php环境本身,但缺点也很明显:检查并

http://www.vimer.cn/2011/01/vimgvim%E9%85%8D%E5%90%88zendcodeanalyzer%E6%A3%80%E6%9F%A5php%E8%AF%AD%E6%B3%95.html


本博之前有写过一篇vim+php.exe检查php语法的文章-在vim中检查php语法格式,这种方式的优点是只依赖php环境本身,但缺点也很明显:检查并不严格,很多错误检查不出来。

所以我们考虑使用另一个语法检查工具-ZendCodeAnalyzer.
博友梧桐之前在博客中咨询该怎么写ZendCodeAnalyzer的errorformat,所以这里放出代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<span>map</span> <span>F7<span>></span> <span>:</span><span>call</span> CheckPHPSyntax<span>(</span><span>)</span><span>CR<span>></span>
<span>function</span> CheckPHPSyntax<span>(</span><span>)</span>
    <span>let</span> php_check_syntax_cmd=<span>'ZendCodeAnalyzer  --disable var-arg-unused'</span>
 
    <span>let</span> exeFile = <span>expand</span><span>(</span><span>"%:t"</span><span>)</span>
    <span>let</span> <span>&</span>makeprg = php_check_syntax_cmd
    set errorformat=<span>%</span>f<span>(</span><span>line</span>\ <span>%</span>l<span>)</span><span>:</span>\ <span>%</span>m
    silent make <span>%</span>
    <span>if</span> <span>len</span><span>(</span><span>getqflist</span><span>(</span><span>)</span><span>)</span><span>></span><strong>2</strong>
        <span>call</span> <span>setqflist</span><span>(</span><span>remove</span><span>(</span><span>getqflist</span><span>(</span><span>)</span>,<strong>2</strong>,<span>-</span><strong>1</strong><span>)</span><span>)</span>
        copen
    <span>else</span>
        cclose
        normal <span>:</span>
        <span>echohl</span> WarningMsg <span>|</span> <span>echo</span> <span>"Check over,No error!"</span> <span>|</span> <span>echohl</span> None
    <span>endif</span>
endf</span></span>

把ZendCodeAnalyzer放到环境变量中后,在vim中按下F7即可调用进行语法检查了,如下图:

vim(gvim)配合ZendCodeAnalyzer检查php语法

由于网站流量的限制,ZendCodeAnalyzer的windows和linux版本就不放出下载了,大家有需要在下面留言即可,我晚上会统一发送。

附:
其实这里还有个遗憾,就是没能做成像pyflakes一样的实时语法检查,之前尝试过实时检查,发现每次启动进程速度还是太慢了,可能需要考虑新的方法,这里如果有博友有好方法,欢迎不吝告知


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn