#27406 [Asn]: php_check_syntax executes code
| From: | philip@php.net | Date: | Tue, 25 Jan 2005 18:56:40 +0000 |
| Subject: | #27406 [Asn]: php_check_syntax executes code | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-72797@lists.php.net to get a copy of this message | ||
ID: 27406
Updated by: philip@php.net
Reported By: thomas at stauntons dot org
Status: Assigned
Bug Type: Unknown/Other Function
-Operating System: OS X
+Operating System: All
PHP Version: php5.0-200412100930
-Assigned To: iliaa
+Assigned To: ilia
New Comment:
It's like include() except it won't output the "checked" file (like if
the "checked" file has an echo, it won't echo it). Aside from the
obvious that's the only difference I notice but haven't tested it
thoroughly.
Sounds like this bug will never be fixed so I guess we should just
document the current behavior.
Previous Comments:
------------------------------------------------------------------------
[2004-12-14 00:30:08] andi@php.net
I see it's assigned to Ilia so I'm not changing the status. Personally
I would put this on very low priority for resolving. Whoever added the
lint functionality probably did it for the command-line PHP in order to
be able to quickly check a large amount of source code. I don't see this
as a mainstream feature of PHP and would avoid hacking on getting it
right as to not intefere with the normal execution of PHP (although
it's quite possible).
------------------------------------------------------------------------
[2004-12-10 17:39:51] philip@php.net
See also: http://bugs.php.net/27728
------------------------------------------------------------------------
[2004-11-11 23:34:56] jimmy dot lantz at gmail dot com
Couldnt there be an optional bool for including the function? Like
bool php_check_syntax ( string file_name [, string &error_message][,
bool just_lint])
That is if 3rd var is true it behaves like php -l from CLI?
That way we that just wants to validate PHP code without
including/running it?
Preferrably in a totally secured way...
------------------------------------------------------------------------
[2004-10-22 23:37:44] dan dot ostrowski at gmail dot com
The person above posted this:
----------------------
<?php
$error_message = "";
$filename = "./tests.php";
//Check out $filename
if(!php_check_syntax($filename, $error_message)) {
//Display an error message, the code is bad
printf("Errors were found in the file %s:\n\n%s\n",
$filename,
$error_message);
} else {
//Execute the valid code
include_once ($filename);
}
-------------------------
To use in the docs. The problem is this code is INCORRECT.
The function php_check_syntax( ) INCLUDES THE FILE in php
5.0.2
This means you get redeclare errors if you try to check the
syntax and then include the file.
The example code SHOULD be:
-----------------
<?php
$filename = '/path/to/somefile.php';
$err = (string) null;
if( !php_check_syntax( $filename, $err ) ) {
print "Syntax Error!"
die( );
}
// proceed, because at this point the file is included
// or script is dead.
-----------------------------
------------------------------------------------------------------------
[2004-10-07 16:07:50] junk at thinkof dot net
My vote is for this function, and for updating the docs. Also the
comments in the php.net manual should be updated, as this isn't really
a bug.
Simply saying that the function is being misused, or saying this is bug
is not a good thing. People just need to understand its usage.
The simplest way I can see of updating the doc, is including a more
useful example. Perhaps mentioning possible usages (checking the
syntax of a file for it's first load into a caching engine for
example).
<?php
$error_message = "";
$filename = "./tests.php";
//Check out $filename
if(!php_check_syntax($filename, $error_message)) {
//Display an error message, the code is bad
printf("Errors were found in the file %s:\n\n%s\n", $filename,
$error_message);
} else {
//Execute the valid code
include_once ($filename);
}
?>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/27406
--
Edit this bug report at http://bugs.php.net/?id=27406&edit=1