470,848 Members | 1,321 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Tool to parse and validate PHP script?

Hello

Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?

I just noticed that I copy/pasted some code that had lines longer that
can fit in the SSH terminal window, and that caused a run-time error
as reported in the /var/log/httpd-error.log but not in the browser:

[error] PHP Notice: Undefined index: etablissemen\nt in
/usr/local/www/apache22/data/prospect.php on line 49, referer:
http://server/myscript.php

Thank you.
Jun 2 '08 #1
13 1713
Gilles Ganault wrote:
Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?

I just noticed that I copy/pasted some code that had lines longer that
can fit in the SSH terminal window, and that caused a run-time error
as reported in the /var/log/httpd-error.log but not in the browser:

[error] PHP Notice: Undefined index: etablissemen\nt in
/usr/local/www/apache22/data/prospect.php on line 49, referer:
http://server/myscript.php
You can run 'php -l thescript.php' to do a syntax check, however your
error would not be catched by that: this is a run time error, and only
catchable by actually running the script.

Of course, on live websites error should not be shown, but logged, as is
done her apparently.
--
Rik Wasmus
Jun 2 '08 #2
On May 8, 9:06 am, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
Gilles Ganault wrote:
Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
I just noticed that I copy/pasted some code that had lines longer that
can fit in the SSH terminal window, and that caused a run-time error
as reported in the /var/log/httpd-error.log but not in the browser:
[error] PHP Notice: Undefined index: etablissemen\nt in
/usr/local/www/apache22/data/prospect.php on line 49, referer:
http://server/myscript.php

You can run 'php -l thescript.php' to do a syntax check, however your
error would not be catched by that: this is a run time error, and only
catchable by actually running the script.

Of course, on live websites error should not be shown, but logged, as is
done her apparently.
--
Rik Wasmus
Any chance to transfer your file by ftp or sftp?
Jun 2 '08 #3
On Thu, 8 May 2008 06:14:40 -0700 (PDT), ELINTPimp wrote:
>Gilles Ganault wrote:
Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
I just noticed that I copy/pasted some code that had lines longer that
can fit in the SSH terminal window, and that caused a run-time error
as reported in the /var/log/httpd-error.log but not in the browser:
[error] PHP Notice: Undefined index: etablissemen\nt in
/usr/local/www/apache22/data/prospect.php on line 49, referer:
http://server/myscript.php

Any chance to transfer your file by ftp or sftp?
Or use a better configuration on the editor....

--
This was, apparently, beyond her ken. So far beyond her ken that she was
well into barbie territory.
-- J. D. Baldwin
Jun 2 '08 #4
ELINTPimp wrote:
On May 8, 9:06 am, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
>Gilles Ganault wrote:
>> Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
I just noticed that I copy/pasted some code that had lines longer that
can fit in the SSH terminal window, and that caused a run-time error
as reported in the /var/log/httpd-error.log but not in the browser:
[error] PHP Notice: Undefined index: etablissemen\nt in
/usr/local/www/apache22/data/prospect.php on line 49, referer:
http://server/myscript.php
You can run 'php -l thescript.php' to do a syntax check, however your
error would not be catched by that: this is a run time error, and only
catchable by actually running the script.

Of course, on live websites error should not be shown, but logged, as is
done her apparently.

Any chance to transfer your file by ftp or sftp?
What do you mean? 'my file'?

--
Rik Wasmus
Jun 2 '08 #5
On Thu, 8 May 2008 06:14:40 -0700 (PDT), ELINTPimp <sm*****@gmail.com>
wrote:
>Any chance to transfer your file by ftp or sftp?
I could do that instead. I'll just have to remember to convert from
CRLF to CR.

Thanks for the "-l" switch.
Jun 2 '08 #6
On May 8, 9:59 am, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
ELINTPimp wrote:
On May 8, 9:06 am, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
Gilles Ganault wrote:
Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
I just noticed that I copy/pasted some code that had lines longer that
can fit in the SSH terminal window, and that caused a run-time error
as reported in the /var/log/httpd-error.log but not in the browser:
[error] PHP Notice: Undefined index: etablissemen\nt in
/usr/local/www/apache22/data/prospect.php on line 49, referer:
http://server/myscript.php
You can run 'php -l thescript.php' to do a syntax check, however your
error would not be catched by that: this is a run time error, and only
catchable by actually running the script.
Of course, on live websites error should not be shown, but logged, as is
done her apparently.
Any chance to transfer your file by ftp or sftp?

What do you mean? 'my file'?

--
Rik Wasmus
Sorry, Rik, I replied to the wrong comment. I was referring to the
posters copy/paste method being the problem and skip the need for
checking this post-transfer altogether by transferring the file they
created (and presumably tested) instead of copy/paste over ssh.
Jun 2 '08 #7
Gilles Ganault wrote:
On Thu, 8 May 2008 06:14:40 -0700 (PDT), ELINTPimp <sm*****@gmail.com>
wrote:
>Any chance to transfer your file by ftp or sftp?

I could do that instead. I'll just have to remember to convert from
CRLF to CR.
I often work under Windows, however, even under Windows my editor is set
up to \n instead of \r\n all the time. Saves a lot of headaches.

--
Rik Wasmus
Jun 2 '08 #8
Rik Wasmus wrote:
Gilles Ganault wrote:
>On Thu, 8 May 2008 06:14:40 -0700 (PDT), ELINTPimp <sm*****@gmail.com>
wrote:
>>Any chance to transfer your file by ftp or sftp?

I could do that instead. I'll just have to remember to convert from
CRLF to CR.

I often work under Windows, however, even under Windows my editor is set
up to \n instead of \r\n all the time. Saves a lot of headaches.
A text mode transfer will automatically strip or add \r as necessary.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #9
Gilles Ganault wrote:
Hello

Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
You will never have a compile-time error with PHP since PHP is a script
and, hence, doesn't compile. Perhaps you mean run-time issues?
Jun 2 '08 #10
On Thu, 08 May 2008 17:22:59 -0400, sheldonlg <sheldonlgwrote:
>You will never have a compile-time error with PHP since PHP is a script
and, hence, doesn't compile. Perhaps you mean run-time issues?
No, I meant syntax errors that could be picked by just parsing the
source, so those simple issues are detected before actualling running
the program. "php -l" did the trick (along with "... or die" to detect
faulty SQL commands). Thanks.
Jun 2 '08 #11
Gilles Ganault wrote:
On Thu, 08 May 2008 17:22:59 -0400, sheldonlg <sheldonlgwrote:
>>You will never have a compile-time error with PHP since PHP is a script
and, hence, doesn't compile. Perhaps you mean run-time issues?

No, I meant syntax errors that could be picked by just parsing the
source, so those simple issues are detected before actualling running
the program. "php -l" did the trick (along with "... or die" to detect
faulty SQL commands). Thanks.
some editors have syntax checking, as for example jEdit (www.jedit.org) with
phpparser plugin installed.

--
a.d.
Jun 2 '08 #12
Sir Robin wrote:
On Thu, 08 May 2008 17:22:59 -0400, sheldonlg <sheldonlgwrote:
>Gilles Ganault wrote:
>>Hello

Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
You will never have a compile-time error with PHP since PHP is a script
and, hence, doesn't compile. Perhaps you mean run-time issues?

As far as I understand PHP does in fact first compile the script to byte-code
and then run it... Surely if the code has syntax errors it would result to
compile time error, right?
No, Gilles is correct. PHP is not compiled. It is interpreted. A big
difference. And no, syntax errors are not considered compile-time errors.

Java, OTOH, is compiled to byte code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #13
..oO(Jerry Stuckle)
>Sir Robin wrote:
>On Thu, 08 May 2008 17:22:59 -0400, sheldonlg <sheldonlgwrote:
>>Gilles Ganault wrote:
Hello

Is there a tool on Linux/FreeBSD that can parse a PHP script to make
sure there's no compile-time issues?
You will never have a compile-time error with PHP since PHP is a script
and, hence, doesn't compile. Perhaps you mean run-time issues?

As far as I understand PHP does in fact first compile the script to byte-code
and then run it... Surely if the code has syntax errors it would result to
compile time error, right?

No, Gilles is correct. PHP is not compiled. It is interpreted.
It's both (hence some even call PHP an "interpiler"). The source code is
compiled into a byte code, which is then interpreted by the Zend engine.
Two steps, two different things.

Caches like APC for example store the _compiled_ code.
>A big
difference. And no, syntax errors are not considered compile-time errors.
It's the parser which chokes upon them, not the interpreter. So they can
be called compile-time errors.
>Java, OTOH, is compiled to byte code.
Which is then executed/interpreted by the VM. Quite similar to PHP, just
done more independently.

Micha
Jun 2 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by ab3331 | last post: by
26 posts views Thread by webrod | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.