note 93060 added to function.die
| From: | DamienBezborodov at osu1 dot php dot net | Date: | Fri, 21 Aug 2009 05:41:10 +0000 |
| Subject: | note 93060 added to function.die | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159727@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 117.55.229.1
Probable Submitter: 210.10.53.49
----
Manual Page -- http://www.php.net/manual/en/function.die.php
Edit -- https://master.php.net/note/edit/93060
Del: integrated -- https://master.php.net/note/delete/93060/integrated
Del: useless -- https://master.php.net/note/delete/93060/useless
Del: bad code -- https://master.php.net/note/delete/93060/bad+code
Del: spam -- https://master.php.net/note/delete/93060/spam
Del: non-english -- https://master.php.net/note/delete/93060/non-english
Del: in docs -- https://master.php.net/note/delete/93060/in+docs
Del: other reasons-- https://master.php.net/note/delete/93060
Reject -- https://master.php.net/note/reject/93060
Search -- https://master.php.net/manage/user-notes.php