473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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_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 /* cr******@dcc.uchile.cl */
One cannot be l33t and clueful at the same time !
-- James Edwards, full-disclosure
Jul 17 '05 #1
1 1608
Cristian Gutierrez wrote:
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?
AFAIK no.

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:
[...]


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.php" 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
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
by: Philipp Lenssen | last post by:
I've tested some of the new Nokia 6600 functionality. It ships with WAP2 and XHTML Support (it says). What it does is check the Doctype -- if it's not the XHTML Mobile Profile Doctype, but a...
9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
13
by: Kieran | last post by:
I am designing a content management system and I want to make sure all pages entered into it's database by users are using valid HTML. I have designed the system to use HTML 4.01 Transitional...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
2
by: Gultekin Komanli | last post by:
Hi All, When I use "option strict on" the lines below are producing errors ("implicit conversion"). chkMove.Checked = RegKey.GetValue(C_RK_MOVEFILES, False) txtUserName.Text =...
3
by: David Mathog | last post by:
I have a program for which this line: if(! lstrtol(&atoken,length-2,(long *) &(lclparams->pad)) || (lclparams->pad< 0)){ generates the warning below, but ONLY if the gcc compiler is at -O2 or...
8
by: Rory Becker | last post by:
A wise man once said: "Never put off until runtime what you can fix at compile time." Actually I think he said it about 10 minutes before I started this post. I am a firm believer, like the...
7
by: Bobby Edward | last post by:
To use XHTML Strict all I have to do is... 1. Add this to the top of my master page/ASPX page(s) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2. ...
92
by: Erwin Moller | last post by:
Hi group, I encoutered page validation error, but I don't know a way around. The page has the following doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
6
by: virtualweb | last post by:
Hi all. I am a self-taught beginner Perl programmer. Run into this snippet of code which works as an Email List Cleaner. The script first checks the sintax of a list of emails saved in an input.txt...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.