The
-l option to PHP on the command line compiles but does not run the code in the file - so it's very useful for syntax checking your code.
Here's an example where I tested a file with a deliberate mistake:
-bash-3.2$ php -l wsse.php
Parse error: syntax error,
unexpected '{', expecting '(' in wsse.php on line 11
Errors parsing wsse.php
-bash-3.2$
And here's the results once I have corrected that:
-bash-3.2$ php -l wsse.php
No syntax errors detected in wsse.php
-bash-3.2$
The -l is the letter "l" - it stands for "lint". Lint was originally a program that was used in conjunction with C code on Unix systems, its purpose being to highlight things in the source code which weren't errors as such, but were highly questionable - to help you mop up little accidents before they happened, or to apply a bandage to a wound in the code before it became serious.
These days, the
gcc compiler supports options such as
-W to turn on warnings, and
-ansi -pedantic to check for ANSI portability, and lint has been superseded.
Another useful code tidy program I've used in the past (for C) has been
cb - the "Code Beautifier". That seems to have faded out like lint, but the
indent program which (as the name suggests) indents your C blocks is still very much with us. And there are a lot of other options to indent too.
Tools for tidying up your PHP? ... have a look at the --with-tidy option when you build PHP; it's included in the distribution from PHP 5.
(written 2010-02-22, updated 2010-03-03)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H114 - Sourcing, installing and configuring PHP [192] Current MySQL and PHP paths and upgrades - (2005-01-28)
[316] Development Environments - (2005-05-19)
[481] PHP upgrade - traps to watch - (2005-10-31)
[934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
[1667] Checking server performance for PHP generated pages - (2008-06-06)
[1688] cannot restore segment prot after reloc message - PHP / httpd - (2008-06-26)
[1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
[1768] What is built in to this httpd and PHP? - (2008-08-23)
[1936] Quick Summary - PHP installation - (2008-12-12)
[2317] How to make a Risotto (PHP build style) - (2009-08-02)
[2433] Controlling, supressing, enabling PHP error messages - (2009-10-02)
[2589] Your PHP code does not work? Here is where to start looking. - (2010-01-18)
[3132] Virtual Hosting with Apache http server - an overall scheme, and avoiding common pitfalls - (2011-01-14)
[3635] Parse error: parse error, unexpected T_STRING on brand new web site - why? - (2012-03-03)
[3955] Building up from a small PHP setup to an enterprise one - (2012-12-16)
[4319] PHP - some quick fixes if scripts have issues, and how to use our support - (2014-11-19)
[4437] Adding a PHP build option, rotating an image based on camera data, and a new look at thumbnails in PHP - (2015-02-22)
C239 - C and C based languages - Putting it all together [836] Build on what you already have with OO - (2006-08-17)
[925] C++ - just beyond the basics. More you can do - (2006-11-14)
[945] Code quality counts - (2006-11-26)
[1181] Good Programming practise - where to initialise variables - (2007-05-09)
[2673] Multiple Inheritance in C++ - a complete example - (2010-03-12)
[2674] Make and makefiles - a commented example to help you learn - (2010-03-12)
[2851] Further C++ material - view new or old - (2010-07-04)
[3067] Using C and C++ functions in the same program - how to do it - (2010-11-24)
[3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
[3252] C++ - unknown array size, unknown object type. Help! - (2011-04-17)
[3810] Reading files, and using factories to create vectors of objects from the data in C++ - (2012-07-21)
[4326] Learning to program - comments, documentation and test code - (2014-11-22)
[4374] Test driven development, and class design, from first principles (using C++) - (2014-12-30)
[4559] When do I use the this keyword in C++? - (2015-10-29)
Some other Articles
Getting a phone line changed ...Length, size or capacity in Java?Java arrays - are they true arrays or not?Removing duplicates from a MySQL tableCompile but do not run PHP - syntax check onlyOptimising and caching your MySQL enquiriesCounting rows in joined MySQL tablesRelating tables with joins in MySQLWhat does a web application look like under Tomcat?Object Oriented Programming in PHP