How to check PHP syntax using the command line

If you're using php for web development, you may want to check  syntax of your file without opening it on web browser.

PHP command-line interface (CLI) includes a nifty option to quickly check for any syntax errors in a source code file. A simple check for a single file is given below. The option flag to check is -l (lowercase ‘L’).

$ php -l example.php

If the file contains no syntax errors, the CLI returns the following message.

No syntax errors detected in example.php


If there is an error in the code the CLI will return the error depending on the context of the error.

Parse error: syntax error, unexpected '$var' (T_VARIABLE) in example.php on line:6
Errors parsing example.php

No comments:

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...