note 93060 deleted from function.die by danbrown
| From: | danbrown@php.net | Date: | Fri, 21 Aug 2009 13:22:39 +0000 |
| Subject: | note 93060 deleted from function.die by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159733@lists.php.net to get a copy of this message | ||
Note Submitter: Damien Bezborodov
----
Beware that when using PHP on the command line, die("Error") simply prints
"Error" to STDOUT and terminates the program with a normal exit code of 0.
If you are looking to follow UNIX conventions for CLI programs, you may consider the following:
<?php
fwrite(STDERR, "An error occurred.\n");
exit(1); // A response code other than 0 is a failure
?>
In this way, when you pipe STDOUT to a file, you may see error messages in the console and BASH
scripts can test for a response code of 0 for success:
rc@adl-dev-01:~$ php die.php > test
An error occurred.
rc@adl-dev-01:~$ echo $?
1
Ideally, PHP would write all Warnings, Fatal Errors, etc on STDOUT, but that's another story.