The exit construct can be used to pass a return code to the executing environment.
#!/usr/bin/php
if ($argv[1] === "bad") {
exit(1);
} else {
exit(0);
}
By default an exit code of 0
will be returned if none is provided, i.e. exit
is the same as exit(0)
. As exit
is not a function, parentheses are not required if no return code is being passed.
Return codes must be in the range of 0 to 254 (255 is reserved by PHP and should not be used). By convention, exiting with a return code of 0
tells the calling program that the PHP script ran successfully. Use a non-zero return code to tell the calling program that a specific error condition occurred.