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

1.1k views Asked by At

While writing a phing xml code to build a php project. Is there any way to find errors in particular project file using phing xml.

We found the code as below only throw alert for syntax error we need to filter it for all php errors like fatal errors & warnings & syntax errors.

the code as below :

  <target name="build">

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

 </target>
2

There are 2 answers

0
Abdul Vahaf On

This is the code to validate php syntax & fatal error while creating build and stop the build if has any error.

<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>
1
Nev Stokes On

Firstly, I'd check out the PhpLintTask instead of running php -l to lint your code. Secondly, the only way to pick up run time errors is to actually run your code. Maybe have a look at using phpunit or Codeception for acceptance testing?