strict checks with php -l

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cristian Gutierrez

    strict checks with php -l

    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_synta x() 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('includ e_path', ini_get('includ e_path').":". ".");
    | ini_set("displa y_errors","1");
    | error_reporting (E_ALL | E_STRICT);
    |
    | array_shift($ar gv);
    | foreach ($argv as $file) {
    | if (!php_check_syn tax($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.uc hile.cl */
    One cannot be l33t and clueful at the same time !
    -- James Edwards, full-disclosure
  • Hilarion

    #2
    Re: strict checks with php -l

    Cristian Gutierrez wrote:
    [color=blue]
    > 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_synta x() over the file?[/color]

    AFAIK no.

    [color=blue]
    > 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:
    > [...][/color]

    Those notice messages are only available on runtime cause only
    then one can check for sure if some variable was set (or some constant
    was defined). Those notices have nothing to do with syntax.

    For example your "testerr.ph p" script could be included by other
    script which would (prior to including) set value of variable $a and
    define constant "a", so there would be no notices.


    Hilarion

    Comment

    Working...