Attached file, implements validate_file(), which implements a php space syntax
check for PHP scripts. It returns a boolean true/false value indicating
whether the script has parse errors or not. Essentially a "php -l" from
within PHP.
strip_file() is added for completion (might as well :) ) and implements "php
-w", which strips comments & whitespace from a PHP file. A quick obfuscater
of sorts.
Any comments?
Ilia
Hi,
Any comments?
I find that useful for something I am writing right now and I was about
to
propose that myself :). I'd go for php_check_syntax() or at least
file_validate() and php_strip_whitespace()
or at least
file_strip_whitespace(), but that's not too important here.
+1 if anyone cares,
Jan
Q: Thank Jan? - A: http://geschenke.an.dasmoped.net/ |
Editor-in-Chief |
"We cats are very independent. We need nobody, no time, | PHP
Magazine |
no where, no way. Isn't that right Pooky?" - Garfield
Key Fingerprint 7BCC EB86 8313 DDA9 25DF 1805 ECA5 BCB7 BB96 56B0
I think it's a very bad idea to start copying lexer code into basic_functions.c
I don't have time to look into it but there must be a cleaner way of doing it.
Andi
At 11:24 AM 11/19/2003 -0500, Ilia Alshanetsky wrote:
Attached file, implements validate_file(), which implements a php space
syntax
check for PHP scripts. It returns a boolean true/false value indicating
whether the script has parse errors or not. Essentially a "php -l" from
within PHP.strip_file() is added for completion (might as well :) ) and implements "php
-w", which strips comments & whitespace from a PHP file. A quick obfuscater
of sorts.Any comments?
Ilia
At 05:30 PM 11/19/2003 +0100, Jan Lehnardt wrote:
Hi,
Any comments?
I find that useful for something I am writing right now and I was about to
propose that myself :). I'd go for php_check_syntax() or at least
file_validate() andphp_strip_whitespace()
or at least
file_strip_whitespace(), but that's not too important here.+1 if anyone cares,
If we're talking about naming the how about script_*?
Andi
If we're talking about naming the how about script_*?
script_* is good, I have no naming preference. I am more interested to know
whether this functionality is something we need or not...
Ilia
Ilia Alshanetsky wrote:
script_* is good, I have no naming preference. I am more interested to know
whether this functionality is something we need or not...
it is not needed, you can just do
system("php -l filename");
instead ;)
actually i would love to have php_check_syntax() as
it would simplify my CVS commit check scripts but i
would like to have it return the actual error message
as string on errors
IMHO it should be php_check_syntax() and not
script_check_syntax() to make clear what it actualy
checks (it won't check the syntax of my shell, awk
or perl scripts, would it? ;)
--
Hartmut Holzgraefe <hartmut@php.net
Ilia Alshanetsky wrote:
script_* is good, I have no naming preference. I am more interested to
know whether this functionality is something we need or not...it is not needed, you can just do
system("php -l filename");
instead ;)
Sure, but that's slow and more importantly, not everyone has access to php-cgi
/ php-cli to perform this action. Heck, many people do cannot use
exec,shell_exec,system,etc... functions because their providers disallow
execution funcitons.
IMHO it should be php_check_syntax() and not
script_check_syntax() to make clear what it actualy
checks (it won't check the syntax of my shell, awk
or perl scripts, would it? ;)
Good idea, we already have some function that utilize php_ prefix, might as
well continue with the trend. How about php_lint() & php_strip()?
Good idea, we already have some function that utilize php_ prefix, might as
well continue with the trend. How about php_lint() & php_strip()?
php_lint() sounds goodr, and I'm cool with either php_strip() or
php_strip_whitespace()
.
I can see these functions being useful in various (albeit rare)
situations.
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)
On Wed, Nov 19, 2003 at 11:24:56AM -0500, Ilia Alshanetsky wrote :
Attached file, implements validate_file(), which implements a php space syntax
check for PHP scripts. It returns a boolean true/false value indicating
whether the script has parse errors or not. Essentially a "php -l" from
within PHP.
As someone else already suggested, providing the error message would
be a good (=foreseeing) idea.
Maybe it's possible to have something like:
bool php_check_syntax($filename [, &$error_message]);
which returns the error message as the second parameter.
As a sidenote, would streams be supported (http, ftp) ? Or are there
some kind of limitating factors?
- Markus
bool php_check_syntax($filename [, &$error_message]);
I'll need to look at the code, it should be possible to do. Although I'd
prefer to have it return the error rather then return it by reference as an
optional argument.
As a sidenote, would streams be supported (http, ftp) ? Or are there
some kind of limitating factors?
That should be possible as well.
Ilia
It should work out of the box.
--Wez.
As a sidenote, would streams be supported (http, ftp) ? Or are there
some kind of limitating factors?That should be possible as well.
On Wed, Nov 19, 2003 at 03:18:34PM -0500, Ilia Alshanetsky wrote :
bool php_check_syntax($filename [, &$error_message]);
I'll need to look at the code, it should be possible to do. Although I'd
prefer to have it return the error rather then return it by reference as an
optional argument.
I understand. I might think it's just safer so one can assume the
return value (bool) just gives information whether it works or not
and the error message itself is a bonus.
if (!php_check_syntax("myscript.php", &$error_message) {
die ( "myscript.php didn't validaet: $error_message");
}
vs.
if (strlen($error_message = php_check_syntax("myscript.php")) > 0) {
die ( "myscript.php didn't validaet: $error_message");
}
I find the former a somewhat cleaner approach than the latter; or
maybe it's just me.
- Markus