php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78301 exit -1 is valid but exit 1 is syntax error
Submitted: 2019-07-17 07:44 UTC Modified: 2019-07-17 08:16 UTC
From: dams@php.net Assigned: dams (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dams@php.net
New email:
PHP Version: OS:

 

 [2019-07-17 07:44 UTC] dams@php.net
Description:
------------
Using a plus or minus sign allows exit to avoid parenthesis. 

The behavior should be consistent : either parenthesis are always needed, either they are optional. 

Either enforce parenthesis in both cases (suggested modification),
or relax parenthesis usage in both cases.

Same applies to die;

Test script:
---------------
exit  1;  <= syntax error
exit (1)  <= executable code
exit -1;  <= executable code
exit +1;  <= executable code

exit -+-1;  <= executable code

exit -$f;  <= executable code
exit $f;  <= syntax error
exit($f);  <= executable code


Expected result:
----------------
exit and die use parenthesis the same way, with or without minus and plus signs.


Actual result:
--------------
exit and die behaves differently parenthesis with or without minus and plus signs.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-17 08:03 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-07-17 08:03 UTC] nikic@php.net
`exit -1` is `(exit) - 1`. The form without parentheses should probably be deprecated to avoid this kind of confusion.
 [2019-07-17 08:12 UTC] dams@php.net
php -r 'exit (-1);' && echo "minus one" => OK

php -r 'exit -1;' && echo "minus one" => No display

'exit -1' is actually '(exit) - 1'; Since the script ends early with exit, it never reaches the substraction, nor any other following operation, in fact (*, +, &&)...
 [2019-07-17 08:16 UTC] dams@php.net
-Status: Not a bug +Status: Closed -Assigned To: +Assigned To: dams
 [2019-07-17 08:16 UTC] dams@php.net
Exit doesn't take any argument, and ends the script early. -1 is never returned.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Sep 18 14:00:01 2025 UTC