Within PHP, basically have one function that calls another function can there be any method of getting the known as function to exit from the caller function without killing the whole script?
For example, let us say I've some code something similar to:
<?php function funcA() function funcB() ?> <p>This is a few text. Following this text, I am likely to call funcA.</p> <p><?php funcA() ?></p> <p>This is much more text after funcA went.</p>
Regrettably, basically find something within funcB which makes me wish to stop funcA from finishing, I appear to need to exit the whole PHP script. Can there be in whatever way for this?
I realize which i could write something into funcA() to look into the derive from funcB(), but, during my situation, I've no treatments for the items in funcA() I have only treatments for the items in funcB().
To create this situation a bit more concrete during this instance, I'm dealing with WordPress. I'm connecting into the get_template_part() function, and seeking to prevent WordPress from really needing/such as the file with the locate_template() function that's known as after my hook is performed.
Does anybody have advice?
Throw an exception in
funcB that's not handled in
<?php function funcA() catch (Exception $e) function funcB() other things, just //make a move like: throw new Exception('Bang!') ?>
It isn't an solution, however, you could hook another function that will get known as when exit() is asked for "register_shutdown_function('shutdown')". And also to in some way have this get things continue again or complete for your satifaction.
<?php function shutdown() procedures // prior to the script is complete. echo 'Script performed with success', PHP_EOL register_shutdown_function('shutdown') ?>
The only method I see is applying exceptions:
function funcA() function funcB() ?> <p>This is a few text. Following this text, I am likely to call funcA.</p> <p><?php try catch (Exception $e) ?></p> <p>This is much more text after funcA went.</p>
Ugly, however it works in PHP5.