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: 2010-12-29 12:21 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:
Status: Open Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or 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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 15:01:28 2019 UTC