Req #49718 [Sus->Dup]: Add logical combination assignment operators
| From: | cmb@php.net | Date: | Wed, 06 Apr 2022 14:08:26 +0000 |
| Subject: | Req #49718 [Sus->Dup]: Add logical combination assignment operators | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-240705@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=49718&edit=1
ID: 49718
Updated by: cmb@php.net
Reported by: robeddielee at hotmail dot com
Summary: Add logical combination assignment operators
-Status: Suspended
+Status: Duplicate
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *
PHP Version: *
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Closing as duplicate of <https://github.com/php/php-src/issues/8312>.
Previous Comments:
------------------------------------------------------------------------
[2022-04-06 14:07:37] cmb@php.net
Related To: Bug #72266
------------------------------------------------------------------------
[2021-03-23 16:56:26] cmb@php.net
Is there any language which supports C style combined assignment
operators, that also supports &&= and/or ||=? That might have a
reasons. If anybody is interested in these operators, please
pursue the RFC process[1]. For the time being, I suspend this
ticket.
[1] <https://wiki.php.net/rfc/howto>
------------------------------------------------------------------------
[2016-10-04 13:31:40] magnar at myrtveit dot com
I think such operators should be short-circuiting, so that
$A = Fun1() && Fun2() && Fun3();
is equivalent with
$A = Fun1();
$A &&= Fun2();
$A &&= Fun3();
By short-circuiting I mean that, if the left hand side can already determined (false && $X
is always false, while true || $X is always true), the right hand side is not evaluated. In the
example above, if Fun1() returns false, Fun2() and Fun3() is never executed, and if Fun1() returns
true, while Fun2() returns false, Fun3() is never executed, etc.
------------------------------------------------------------------------
[2009-09-29 23:56:29] robeddielee at hotmail dot com
Description:
------------
PHP current supports combination assignment operators for arithmetic, bitwise, and string
operations. These operators include: +=, *=, %=, &=, etc...
PHP should also support combination assignment operators for logical operations such as &&
and ||.
The requested operators are: &&=, and ||=. I would also request XOR, but there doesn't
appear to be a ^^ operator to begin with that isn't spelled out.
NOTE: This is NOT the same request as Bug #12930.
Reproduce code:
---------------
$valid = true;
$valid &&= isCondition1();
$valid &&= isCondition2();
$valid &&= isCondition3();
var_export($valid);
Expected result:
----------------
$valid should be set to boolean true, only if the three conditions evaluate to true. If any
condition evaluates to false, $valid should be set to false.
Actual result:
--------------
PHP Parse error: syntax error, unexpected '='...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=49718&edit=1