Home / Section index | www.icosaedro.it | ![]() |
What you should absolutely know to effectively use PHPLint and PHPLint-on-line:
php -l
" syntax validation may also pass the PHPLint validation.
There are many features of PHP that PHPLint does not (and probably never will)
implement because they are either unsafe or do not allow the static validation
of the source. If you already know other compiled languages like C, Java or C#,
it is better to think at PHPLint as a source compiler rather than a syntax
checker, with the only difference that PHPLint does not generate compiled object code.
require_module
meta-code statement. For example:
The<?php /*. require_module 'standard'; require_module 'standard_reflection'; require_module 'spl'; require_module 'mysql'; require_module 'hash'; require_module 'session'; .*/
standard
module contains very basic PHP declarations that
should be required by any practical PHP program.
so you may check with PHPLint-on-line only very basic programs that do not depends on external packages. You may download the stand-alone PHPLint program if you want to check more complex programs that may involve several source files.<?php require_once "my/path/mylib.php"; # NOT ALLOWED UNDER PHPLINT-ON-LINE
For recursive functions and other mutually dependent declarations, see the Recursive declarations chapter of the reference manual.<?php function parseWord($w){ ... } function parseLine($l){ ... parseWord() ... } function parseText($t){ ... parseLine() ... } # Main program: $t = (string) $_POST["text"]; parseText($t);
or you may use a DocBlock as well:<?php /*. void .*/ function f(/*. int .*/ $i, /*. string .*/ $s) /*. throws SomeException, AnotherException .*/ { ... }
For parameters that have a default value, the type of the default value already provides the type of the parameter to PHPLint, so an explicit declaration is not mandatory in this case and can be omitted for brevity:<?php /** @param int $i @param string $s @return void @throws SomeException @throws AnotherException */ function f($i, $s){ ... }
Here it is obvious that $c is a string and $n is an int number.<?php /*. void .*/ function echoSepLine($c = "*", $n = 80){ ... }
This is because these arrays may contain both strings and arrays, so they are declared under PHPLint as arrays of mixed values. Mixed values cannot be practically used under PHPLint and should be converted to some specific actual type according to the intention of the programmer.<?php $name = (string) $_POST["name"]; $n = (int) $_POST["n"];
/*.(T).*/
tells that the item that follows is intended
to be of the exact type T
, so avoiding any ambiguity of interpretation.
For example:
Note that this type-cast is allowed only in front to the NULL value and the empty array constructor, and it is not allowed in any other context.<?php $s = /*. (string) .*/ NULL; $a = /*. (float[int]) .*/ array(); /*. void .*/ function g($a = /*. (string[int]) .*/ array()){ ... }
new $myclass()
are not allowed.
WRONG GOOD if( $a == $b )...
if( $a === $b )...
if( $a == "foo" )...
if( $a === "foo" )...
if( $a != $b )...
if( $a !== $b )...
if( $a < $b )...
if( strcmp($a,$b) < 0 )...
if( $a <= $b )...
if( strcmp($a,$b) <= 0 )...
is not allowed. Choose one of these alternatives instead, depending on what you are really testing for:<?php $s = "some string"; if( ! $s ){ ... } # WRONG
<?php $s = "some string"; if( $s === NULL ){ ... } # if $s is NULL. if( $s === "" ){ ... } # if $s is the empty string. if( strlen($s) == 0 ){ ... } # if $s is NULL or empty.
Umberto Salsi | Comments | Contact | Site map | Home / Section index |
Still no comments to this page. Use the Comments link above to add your contribute.