difference between die and exit in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dinesh1985singh
    New Member
    • Apr 2010
    • 49

    #1

    difference between die and exit in php

    hello everybody,

    I want to know the exact difference between exit and die function in php.I searched it out on google,but didn't find satisfactory answer.I found both are alias of each other,but I guess there must be some difference,so please help me out.


    Thanks...
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    There is no difference. Simple :)

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      the only notable difference is this pun:
      Also note that it is your responsibility to die() if necessary.
      (ref.)

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        This is actually a question in w3schools.org's PHP quiz.

        I remember missing that question and that's why I always remember this.





        Dan

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Code:
          Result:
          
          20 of 20
          100%
          
          Perfect!!!
          
          Time Spent
          1:57
          Sweeeet ;)

          Comment

          • virusaharmer
            New Member
            • Nov 2012
            • 1

            #6
            die function kill the rest all the page and exit will just jump to next line or next function...that s differnce between in both

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              I doubt that. from the Manual:
              [exit] Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.

              Comment

              • solutionwand
                New Member
                • Dec 2012
                • 16

                #8
                Hi,
                There is no difference in functionality. They can be used alternatively with following conditions.

                die > is used to throw an exception (catchable using eval).
                exit > is used to exit the process.

                die > will set the error code based on $! or $? if the exception is uncaught.
                exit > will set the error code based on its argument.

                In short,

                die > outputs a message
                exit > does not outputs message

                Hope this shall help you to understand the difference.

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  die > is used to throw an exception (catchable using eval).
                  wrong. neither does die throw an Exception, nor does eval catches one.

                  let’s get some more precise and quote the Manual:

                  die:

                  Description

                  This language construct is equivalent to exit().

                  exit:

                  Description
                  void exit ([ string $status ] )
                  void exit ( int $status )

                  Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called.

                  exit is a language construct and it can be called without parentheses if no status is passed.

                  Comment

                  • Owais Arain
                    New Member
                    • Jul 2015
                    • 2

                    #10
                    echo also outputs a message #solutionwand

                    Comment

                    • Owais Arain
                      New Member
                      • Jul 2015
                      • 2

                      #11
                      Sorry i m so late, i didn't see the date of this post. :P

                      Comment

                      Working...