0 0 Votes

PHP: Abort within include - continue remaining script

Question by Guest | 24/07/2016 at 10:45

I have a PHP script in which another script is inserted using include('script.php'). So far, it is working like I want.

However, the script included with include() should be canceled and discontinued under some circumstances.

Of course, I could no formulate if-statements for each condition, but this would make the script much more complicated because of the brackets would have to appear again at the end.

So, what I need is something like an exit-command. I have also already tried to use the exit and break functions of PHP, but this always breaks the entire script and not only the included one. The original script from which the include was called, should be continued further in each case.


Stefan Trost

Show Profile | Message
0Best Answer
0 Votes

Just try to use "return". With this, you can write as much termination conditions for your script as you want. Here is an example:

// the included script

if (...) return; // termination condition 1
if (...) return; // termination condition 2

// here the actual code of the script begins
// ...
// ...

The actual code of the script will only be executed in that case if the "return" has not been triggered before. The superordinate script from which this script was called, will not be affected from that.

Another tip: It would be better to include the termination conditions in the super script because then you can save the processor from calling include(). This is better for your performance because the script file must only be searched for when it will also be used.
25/07/2016 at 08:53

ReplyPositive Negative

Related Topics

Abort Windows Batch Script
Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own articles on askingbox.com. How to do.