I've looked at different answers and except for this one that talks about die while testing and generating errors, I want to know if die() has a negative impact on my code when it is useless to continue executing.
For example, if I have a long script with many conditionals, at a given point, once the condition that I was looking for is successful I don't need my script to keep on testing the other conditions.
$a = 'a';
if($a == 'a'){
//long script
die();
}
if($b == 'a'){
//long script
die();
}
if($c == 'a'){
//long script
die();
}
This is a simple and maybe silly example, with other more elegant solutions, but it helps explain my question; if I die()
on the first condition, it will stop from executing the rest of the code, in theory, this should optimize performance, or maybe not...
Is it better to let the script get to the end or die()
will actually speed up the process? If die()
has negative consequences, of course, there are other ways around it, like creating flags to let the script skip certain chunks of code, I just want to know the negative effects of die()
if any.
For example:
- In terms of memory, will die()
keep using memory or maybe it frees up more memory.
- In terms of time/execution will die()
speed up a process because it will not try to execute the rest of the script, or it makes no difference at all. Imagine that down the code there might be a heavy process that can be avoided.
I want to be clear about this, I know there must be many other ways to be more efficient, shorter scripts, switches, flags, etc. I just want to understand if there is any negative impact of using die()
.
Thanks