0

I am trying to create a system where by adding one include, I can set PHP to display errors (the php.ini file prevents this). In other words:

<?php
    include "showerrors.php";
    // Produce Error
    ERROR;
?>

This would create a parse error and "showerrors.php" does not get executed, meaning that the error never gets shown. However, if "showerrors.php" does get executed, the error would be shown.

1
  • Then fix the parse error..... Commented Jan 10, 2013 at 13:36

3 Answers 3

1

If you have a parse error, i.e. invalid syntax, then no code in the file will be executed because the file can't be parsed. That includes include statements. As simple as that, no way around it. It's not difficult to make sure your file has at least correct syntax, such tools are integrated into most editors and IDEs.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, I'm using Notepad++ so I don't have anything to tell me I'm going wrong. That means that in some circumstances, when there is a typo in the code, I have nothing to tell me where I have gone wrong. This means that it could take hours to find.
Then either get a better editor or look at your server's error logs. The error is being reported somewhere. You can also always run your PHP files through the commandline php app for a syntax check. I'd be surprised if Notepad++ didn't have a "Check PHP syntax" command somewhere.
Notepad++ is just a text editor, it has lots of plugins available, but I haven't looked through them yet.
1

You should do exactly the opposite - in showerrors.php turn on error reporting and include the requested file (you can redirect all requests to showerrors.php via mod_rewrite / whatsever supported by the server and then include the requested file)

1 Comment

I'm sorry, I'm relatively new to server side configuration, please could you go into more detail about how your solution works?
0

If there is a parse error, PHP can't execute. Asking if you can force PHP to continue to execute after an error is like asking if you can force a car to start even if the engine is blown - it just can't happen.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.