在构建期间检查PHP错误(语法和致命错误和警告)


Check PHP Errors (Syntax & Fatal Error & Warnings) during build

在编写phing xml代码以构建php项目时。有没有任何方法可以使用phingxml在特定的项目文件中查找错误。

我们发现下面的代码只为语法错误抛出警报,我们需要为所有php错误(如致命错误&警告&语法错误。

代码如下:

  <target name="build">
    <apply executable="php" failonerror="true">
        <arg value="-l" />
        <fileset dir="${srcDir}">
            <include name="**/*.php" />
        </fileset>
    </apply>
 </target>

首先,我会检查PhpLintTask,而不是运行php -l来整理代码。其次,发现运行时错误的唯一方法是实际运行代码。也许可以看看使用phpunit或Codeception进行验收测试?

这是验证php语法的代码;创建生成时出现致命错误,如果有任何错误,请停止生成。

<target name="build">
    <foreach param="fname" absparam="abs-fname" target="cat">
            <fileset dir="${srcDir}">
                <include name="**/*.php" />
            </fileset>
        </foreach> 
   </target>
    <target name="cat">
                <exec command="php -f ${abs-fname}"  checkreturn="true" output="output_text.txt" />
    </target>