php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51930 die() returns exit code 0
Submitted: 2010-05-27 14:15 UTC Modified: 2010-05-31 16:17 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ml at vulnscan dot org Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ml at vulnscan dot org
New email:
PHP Version: OS:

 

 [2010-05-27 14:15 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-28 07:49 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2010-05-28 07:49 UTC] aharvey@php.net
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-31 15:02 UTC] 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-31 16:17 UTC] johannes@php.net
You can easily do this in your own code with a simple wrapper:

ml_die($message,$code) {
    echo $message;
    die($code);
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 00:01:27 2024 UTC