Bug #78301 [Com]: exit -1 is valid but exit 1 is syntax error

From: Date: Wed, 17 Jul 2019 08:12:32 +0000
Subject: Bug #78301 [Com]: exit -1 is valid but exit 1 is syntax error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221821@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
 Comment by:         dams@php.net
 Reported by:        dams@php.net
 Summary:            exit -1 is valid but exit 1 is syntax error
 Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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 (*, +, &&)...


Previous Comments:
------------------------------------------------------------------------
[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 (#221821) next »