What is the integer argument in exit?

6

In PHP, when we want to terminate a script, we usually use the exit function.

When we use strings, it terminates the script and prints this string .

Example:

exit('Stack Overflow'); // Stack Overflow

However, if we use a value of type int , it does not return it;

Example:

exit(0); // Nada é retornado

I imagine this should serve some internal functionality of this function.

But what is the purpose of this integer parameter in exit ?

    
asked by anonymous 31.07.2015 / 17:22

3 answers

8

In the PHP manual says:

  

If status is an integer, that value will be used as the exit status and not printed.

That is, if passed an integer it will be used only as status code and not printed on the page. It looks like this from PHP >= 4.2.0 .

    
31.07.2015 / 17:27
7

It returns this value for what it called the PHP script, in this case the shell of the operating system. As far as I know this is of no use if you are using an HTTP server.

Obviously only the shell will know what to do with this error code it will receive from PHP. So there is a semantic difference in this construct when you use a string or a number.

Zero indicates no errors, another number indicates why script failed.

Documentation .

    
31.07.2015 / 17:28
3

If an integer value is passed, nothing is returned. Parameter 0 indicates that the executed code succeeded. Parameter 1 is the opposite, meaning that you hear some error in the code.

    
31.07.2015 / 17:41