php.net |  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
Votes:15
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: robeddielee at hotmail dot com
New email:
PHP Version: OS:

 

 [2009-09-29 23:56 UTC] 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 '='...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-29 12:21 UTC] jani@php.net
-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] cmb@php.net
-Status: Open +Status: Suspended
 [2021-03-23 16:56 UTC] 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>
 [2022-04-06 14:08 UTC] cmb@php.net
-Status: Suspended +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-04-06 14:08 UTC] cmb@php.net
Closing as duplicate of <https://github.com/php/php-src/issues/8312>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 13:01:28 2024 UTC