|
Posted by Cristian Gutierrez on 07/11/05 09:14
Hello all,
Is there any way to trigger "undefined variable/constant" error notices
when running `php -l' over a source file? Or even better, when using
php_check_syntax() over the file?
So far I've noticed that I only get those errors when actually *running*
the script, and I'm beggining to suspect there's little more (if at all)
to do without getting dirty with a PHP language parser. For example,
when I run the following script:
,----[ bin/phpcheck ]
| <?php
| ini_set('include_path', ini_get('include_path').":". ".");
| ini_set("display_errors","1");
| error_reporting(E_ALL | E_STRICT);
|
| array_shift($argv);
| foreach ($argv as $file) {
| if (!php_check_syntax($file, $errors))
| echo $errors;
| }
| ?>
`----
over a file like this:
,----[ tmp/testerr.php ]
| <?
| error_reporting(E_ALL | E_STRICT);
|
| echo $a; // non-defined
| a; // WTF is that?
|
| ?>
`----
I get:
,----
| $ bin/phpcheck tmp/testerr.php
| $
`----
(i.e., nothing)
Same story with `php -l':
,----
| $ php -l tmp/testerr.php
| No syntax errors detected in tmp/testerr.php
`----
But I get all those wonderful notices when actually running the script:
,----
| $ php -f tmp/testerr.php
|
| Notice: Undefined variable: a in /path/to/tmp/testerr.php on line 4
|
| Notice: Use of undefined constant a - assumed 'a' in
| /path/to/tmp/testerr.php on line 5
`----
PHP (installed from source) & OS versions follow:
,----
| $ php -v
| PHP 5.0.4 (cli) (built: May 18 2005 14:21:02)
| Copyright (c) 1997-2004 The PHP Group
| Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
| $ cat /etc/fedora-release
| Fedora Core release 2 (Tettnang)
`----
I appreciate any hints on this.
TIA,
--
Cristian Gutierrez /* crgutier@dcc.uchile.cl */
One cannot be l33t and clueful at the same time !
-- James Edwards, full-disclosure
Navigation:
[Reply to this message]
|