Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Parser errors are fatal errors, so you can't catch them. See this question and answer for more detailsSee this question and answer for more details.

What you can do if you can run exec() is call php -l thefilename.php and check the result. See the manual for information on how this works. There are a few problems here, however:

  • This is extremely dangerous, because you are passing information to the command line. You absolutely must filter any user input very carefully, or you would be giving the user very broad access to your system.
  • exec() is often disabled, as it should be, because of the extremely high security risks of using it incorrectly.
  • There's really no good reason to include a file that you haven't already validated for syntax errors. If this is for plugins or something, then I understand your reasoning. If it is code you have control over, however, you should validate before putting it into production.

Parser errors are fatal errors, so you can't catch them. See this question and answer for more details.

What you can do if you can run exec() is call php -l thefilename.php and check the result. See the manual for information on how this works. There are a few problems here, however:

  • This is extremely dangerous, because you are passing information to the command line. You absolutely must filter any user input very carefully, or you would be giving the user very broad access to your system.
  • exec() is often disabled, as it should be, because of the extremely high security risks of using it incorrectly.
  • There's really no good reason to include a file that you haven't already validated for syntax errors. If this is for plugins or something, then I understand your reasoning. If it is code you have control over, however, you should validate before putting it into production.

Parser errors are fatal errors, so you can't catch them. See this question and answer for more details.

What you can do if you can run exec() is call php -l thefilename.php and check the result. See the manual for information on how this works. There are a few problems here, however:

  • This is extremely dangerous, because you are passing information to the command line. You absolutely must filter any user input very carefully, or you would be giving the user very broad access to your system.
  • exec() is often disabled, as it should be, because of the extremely high security risks of using it incorrectly.
  • There's really no good reason to include a file that you haven't already validated for syntax errors. If this is for plugins or something, then I understand your reasoning. If it is code you have control over, however, you should validate before putting it into production.
Source Link
elixenide
  • 44.9k
  • 16
  • 79
  • 103

Parser errors are fatal errors, so you can't catch them. See this question and answer for more details.

What you can do if you can run exec() is call php -l thefilename.php and check the result. See the manual for information on how this works. There are a few problems here, however:

  • This is extremely dangerous, because you are passing information to the command line. You absolutely must filter any user input very carefully, or you would be giving the user very broad access to your system.
  • exec() is often disabled, as it should be, because of the extremely high security risks of using it incorrectly.
  • There's really no good reason to include a file that you haven't already validated for syntax errors. If this is for plugins or something, then I understand your reasoning. If it is code you have control over, however, you should validate before putting it into production.