ID:               27406
 Comment by:       jimmy dot lantz at gmail dot com
 Reported By:      thomas at stauntons dot org
 Status:           Assigned
 Bug Type:         Unknown/Other Function
 Operating System: OS X
 PHP Version:      5.0.2-dev
 Assigned To:      iliaa
 New Comment:

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...


Previous Comments:
------------------------------------------------------------------------

[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);
}

?>

------------------------------------------------------------------------

[2004-09-21 16:03:24] de_bruut at hotmail dot com

"How should the docs be changed? This misfeature hasn't been dealt with
yet...maybe we should just remove the docs :)"

What misfeature? IMO a function that can check the syntax of a PHP file
before it's included has real benefits for development and testing (as
it can be used to avoid parse and fatal errors etc). And the
documentation of php_check_syntax perfectly describes such a function.
The only problem here is the fact that php_check_syntax not only checks
the code, but executes it as well. I'd say that this is unexpected,
undesirable behavior (a bug). The documentation is just fine the way it
is now...

------------------------------------------------------------------------

[2004-09-20 21:36:57] [EMAIL PROTECTED]

How should the docs be changed? This misfeature hasn't been dealt with
yet...maybe we should just remove the docs :)

------------------------------------------------------------------------

[2004-09-16 18:19:12] didou at keliglia dot com

"So should this function actually execute the code (like an include())
or
should it be a simple lint check (identical to php -l)"

It should do only a lint check, otherway we don't need this function as
we already have include..

Anyway, we should really change the docs philip.

------------------------------------------------------------------------

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

Reply via email to