Register now or log in to join your professional community.
die() and exit() are precisely identical; they halt the entire PHP program and return to the OS. They're two different names for the same function.
return, on the other hand, ends a function call and returns to the caller. At the end of a program, return sets the status value that is returned to the OS; the program is going to exit no matter what.
In PHP, die & exit are the two different names of the same function, both are language construct and equivalent to each other,
although in using both the functions, i have a personal practice.
EXIT()
when i want to end the execution of the script, i use exit.
DIE()
when i need to end the execution due to some problem (e.g. could not connect to db) i use die()
This way, when I see exit at some point in my code, I know that at this point I want to exit because the logic ends here. When I see die, I know that I'd like to continue execution, but I can't or shouldn't due to error in previous execution.
– There is not a single visible difference between these two functions. They both are the same, one is the alias of the other. If at all any one of you can find a real visible difference then I would appreciate if you could post it in the comments section of this blog.
Hi @Adel , thanks for the invitation Sir:-
Both are same because these are construct. They halt the entire PHP program and returns.
According to Die it is Equivalent to Exit. So yes, you can interchange them. Maybe the die function call was created to make Perl programmers feel at home. aliases allows programmers to use the one which is comfortable with. I remember exit better than die. Some others remember die better than exit.
Regards,
Kamal