what is difference between die and exit in php

Many PHP developers are been asked this question in interview. But many times they are not sure about answer.

There is no difference between die() and exit() function. They both are same and worked same.
Again question is why php keep the both functions if they are same. Both functions are alias of each other function.

Due to API and keeping the backward compatibility both functions are kept.

what is difference between die and exit in php

what is difference between die and exit in php

Here is one more example:

is_int() and is_integer() are also same.

There are quite a few functions in PHP which you can call with more than one name. In some cases there is no preferred name among the multiple ones, is_int() and is_integer() are equally good for example. However there are functions which changed names because of an API cleanup or some other reason and the old names are only kept as aliases for backward compatibility. It is usually a bad idea to use these kind of aliases, as they may be bound to obsolescence or renaming, which will lead to unportable script. This list is provided to help those who want to upgrade their old scripts to newer syntax.

Full list of Aliases function you will find on following URL:
http://php.net/manual/en/aliases.php

Add a Comment

Your email address will not be published. Required fields are marked *