[RESOLVED] check php syntax (before include/require)

windows

Guest
I have had some problems trying to check the content of a php file. Maybe you guys could help me..

Ok, to check if a file is a file and is readable is easy enough.
Then, the content COULD contain a parse error, so naturally enough I would like to react on this with my own custom error handler (which works splendid) or check the syntax before including. But, this is not possible.
Facts:
1. both include and require triggers parse errors
2. Those are NOT handled by custom errorhandlers for some reason.
3. php_check_syntax() is removed from v5.0.5.
4. using 'php -l $file' is unhandy and unwanted.
5. using the tokenizer method is not realiable (have tested it a lot!)
6. You just cant suppress the function with @. This results in a blank screen instead and dies.
7. Exceptions is no use here. Doest do any good either.

the prefered method would be something like this, but nothing near it is possible:

if (include($file) == true)
echo "ok, continue";
else
echo "somethings wrong with". $file;my though is you just turn error reporting off completely in the files you want to include, and create some variable in that file to determine if it executed fine.

file_1.php

<?php

echo "before include\n";

include("file_2.php");

if (isset($file2_test)) {
echo "include was okay\n";
} else {
echo "include didnt work\n";
}

echo "after include\n";

?>


file_2.php

<?php
error_reporting(0);

fdsaffs; // causes fatal error

$file2_test = "set"; //always do this at the very end

?>



So that way, you set a variable in the included file, if all worked out okay, the variable will then be set after the include, if it had a parse error, the variable wont exist and you can then see the included failed somehow.hmm. you got a point there ... Have to investigate :)
 
Back
Top