Edit report at http://bugs.php.net/bug.php?id=51930&edit=1
ID: 51930 Updated by: [email protected] Reported by: ml at vulnscan dot org Summary: die() returns exit code 0 Status: Wont fix Type: Bug Package: Unknown/Other Function Operating System: Linux PHP Version: 5.3.2 New Comment: You can easily do this in your own code with a simple wrapper: ml_die($message,$code) { echo $message; die($code); } Previous Comments: ------------------------------------------------------------------------ [2010-05-31 15:02:52] smlerman at gmail dot com Would it make sense to add an overload that takes two parameters? i.e. die([string message, [int status = 0]]) ------------------------------------------------------------------------ [2010-05-28 07:49:50] [email protected] I agree that it doesn't seem terribly logical, but it's been the case for a good ten years or so at this point, so I can't really see the exit code changing now. ------------------------------------------------------------------------ [2010-05-27 14:15:05] ml at vulnscan dot org Description: ------------ die() returns exit status 0 (success), which is IMHO illogical. This mostly matters when using PHP-CLI, for example where you have the usual: @mysql_connect(..) or die('sql blahblah'); ...in that case a success error code is returned. I had this in an authentication callback script which returns 0 on user success and any other value on user failure. In this case it returned 'success' in case of a SQL server error. The only workaround I can see is first printing the error message, and then doing an explicit die/exit with a numerical value. This does not exactly improve code readability/niceness. And, like I said, I simply didn't expect die() to return a success exit code. Test script: --------------- <? die('abc'); ?> Expected result: ---------------- I expect a non-zero exit code, instead of 0 (success). Actual result: -------------- Exit status of 0 (success) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51930&edit=1
