Validate Script but don't execute


#1

I’m trying to use “php -l somescript.php” but have it so it doesn’t repeat when an error is located. I’m trying to run this command from within another script and the returned value is returned to the calling script but what happens if there is an error? The string “PHP Parse error:…” prints followed by the exact string minus “PHP” so “Parse error:…”. How can I suppress the first error that seems to get printed from within the PHP interpreter?


#2

How about just fixing the code so you don’t have any errors.


#3

Because it’s part of a learning tool so I’m looking for feedback from the command without having it duplicated and without having to parse it to get it. If I run the qx function in Perl the returned string is the second string that appears if you run the above command from the command line. The issue is command being run prints out the first line, being “PHP Parse error:…”. I was hoping there was a flag to pass along with the -l to suppress output from within the command but there doesn’t appear to be one.


#4

So nothing helpful then?


#5

How about posting your code. We can’t see your screen.


#6

There is hardly anything to post. Are you familiar with what is returned from using “php -l scriptname.php” if there is an error? I’m not writing out anything I have in Perl as it would just confuse the matter. You can simply run this from the command line to get what I’m referring to (just have a script that has an error in it is all you need).
You get an error that starts with “PHP Parse error:” and then it is followed by the exact line minus “PHP” (so starts with “Parse error:”). This isn’t some specific error that I need help with. I’m wondering how to avoid the first error line that is generated from somewhere within the PHP interpreter. It appears that the first line is printed from within the interpreter while the second is the return value from the call. I would like to suppress the first line if possible - not have the interpreter print anything out.


#7

If there is a PHP parse error, it is because something in that script is fatal. So, kinda need the script to see where it fails.


#8

I’m NOT looking to find a specific error. This is a learning tool. A user will enter their code, save it as a file, and the Perl script I have will do a quick validation of the PHP code they created. The chances of there being an error are rather good considering it is for learning purposes.

I run the “php -l userCreatedScript.php” command from within my Perl script and I want to use the output (from running that command) in a message displayed to the user. In this case though I am receiving two lines back that are essentially the same except the first one starts with “PHP” (as mentioned above). You can write a php script and have <?php garasdsah = 111; ?> in it and run “php -l scriptName.php” and see what I am referring to. You will get two lines.


#9

OP I get what your saying. I am looking into it.

@astonechipher, the lint error shows up twice. OP only wants it to show once. Has something to do with being output to both stderr and stdout.

EDIT: OP, That’s just what it does.

-l --syntax-check

Provides a convenient way to perform only a syntax check on the given PHP code. On success, the text No syntax errors detected in is written to standard output and the shell return code is 0. On failure, the text Errors parsing in addition to the internal parser error message is written to standard output and the shell return code is set to -1.