How to terminate the execution of a script in PHP ?

devquora
devquora

Posted On: Feb 22, 2018

 

To terminate the script in PHP, exit() function is used. It is an inbuilt function which outputs a message and then terminates the current script. The message which is you want to display is passed as a parameter to the exit () function and this function terminates the script after displaying the message. It is an alias function of die () function. It doesn’t return any value.

Syntax: exit(message)

Where massage is a parameter to be passed as an argument. It defines message or status.

Exceptions of exit():

  • If no status is passed to exit(), then it can be called without parenthesis.
  • If a passed status is an integer then the value will not be printed but used as the exit status.
  • The range of exit status is from 0 to 254 where 255 is reserved in PHP.

Errors And Exceptions

  • exit() can be called without parentheses if no status is passed to it. Exit() function is also known by the term language construct.
  • If the status passed to an exit() is an integer as a parameter, that value will be used as the exit status and not be displayed.
  • The range of exit status should be in between 0 to 25. the exit status 255 should not be used because it is reserved by PHP.

 

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PHP Interview Questions

    What is T_PAAMAYIM_NEKUDOTAYIM in PHP?

    T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically, it used to call static methods/variables of a Class...

    PHP Interview Questions

    What is the difference between == and === operator in PHP ?

    In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type...