I think Drupal should avoid using exit calls and let every function ends naturally
drupal_goto and cron calls implies exit calls which aren't clear at all
resulting in bad code style
for instead
function xyz() {
if (...) {
drupal_goto(...);
// this point won't be reached due to drupal_goto calling exit
}
...
return ...;
}
Comments
Comment #1
gpk commentedIn the case you cite, http://api.drupal.org/api/function/drupal_goto/7, we are doing a redirect and so normally there would be no chance for the function to end naturally...
Comment #2
arhak commentedcurrently D7 has more clean
exitcallsas you can see the point where a redirection is decided is not enough argument to abruptly terminate the execution e.g.
drupal_gotogives a chance todrupal_exitto invokehook_exit, nevertheless afterwards it callsexit, which I think should be avoided.as I see it, the only reason to abruptly terminate an execution would be a fatal AND non-recoverable error
even if a fatal error is detected it might be possible to render some output safely without an unnatural termination, but some cases might compromise the stability of the system in which cases an abrupt halt might be appropriated
in any other case, the execution flow should be respected/honored like the original post example illustrates: a disjunctive casuistic path which ends alternatively through
returnordrupal_gotowhich is totally incorrect from a readable code perspectiveComment #3
arhak commenteda live example of what I think is bad practice #720868: drastic drupal_not_found & exit in argument_handler::query
why should a block being rendered invoke
exitin the middle of a function named "query" with a comment stating the purpose of "See if we're outside the allowed date range for our argument" ??this is being encourage by core's code abusing
drupal_not_found&exitif the final outcome of a page dispatch is gonna be a redirect/not found/exit/whatever it might be done letting functions end naturally and executing drastic actions at the end of the entry point (index.php or menu_execute_active_handler, etc) and shouldn't be based on the result being numeric either, it should be something more robust
Comment #4
arhak commentedanother example to illustrate why killing PHP might be a bad idea even when it seems there is nothing else to do #286263: Make search indexing smart to handle nodes wth php redirects
Comment #5
kars-t commentedHi
I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.
Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.
Comment #7
Angry Dan commentedAnother reason why this is bad is if you come to unit test your code. Tests won't complete because the code is exiting. Even if you can justify leaving things as they are for now, drupal_exit should be deprecated in favour of natural code execution.