Bug #78301 [Nab->Csd]: exit -1 is valid but exit 1 is syntax error

From: Date: Wed, 17 Jul 2019 08:16:10 +0000
Subject: Bug #78301 [Nab->Csd]: exit -1 is valid but exit 1 is syntax error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221822@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78301&edit=1

 ID:                 78301
 Updated by:         dams@php.net
 Reported by:        dams@php.net
 Summary:            exit -1 is valid but exit 1 is syntax error
-Status:             Not a bug
+Status:             Closed
 Type:               Bug
 Package:            *General Issues
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        dams
 Block user comment: N
 Private report:     N

 New Comment:

Exit doesn't take any argument, and ends the script early. -1 is never returned.


Previous Comments:
------------------------------------------------------------------------
[2019-07-17 08:12:32] 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:03:14] 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 07:44:13] 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.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78301&edit=1


Thread (4 messages)

« previous php.bugs (#221822) next »