|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49718 Add logical combination assignment operators
Submitted: 2009-09-29 23:56 UTC Modified: 2022-04-06 14:08 UTC
Avg. Score:4.1 ± 1.1
Reproduced:13 of 14 (92.9%)
Same Version:8 (61.5%)
Same OS:8 (61.5%)
From: robeddielee at hotmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2009-09-29 23:56 UTC] robeddielee at hotmail dot com
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();

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 '='...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-29 12:21 UTC]
-Summary: Logical Combination Assignment Operators +Summary: Add logical combination assignment operators -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: Irrelevant +Operating System: * -PHP Version: 5.3.0 +PHP Version: *
 [2016-10-04 13:31 UTC] 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.
 [2021-03-23 16:56 UTC]
-Status: Open +Status: Suspended
 [2021-03-23 16:56 UTC]
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

[1] <>
 [2022-04-06 14:08 UTC]
-Status: Suspended +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-04-06 14:08 UTC]
Closing as duplicate of <>.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Oct 06 08:05:52 2022 UTC