Req #49718 [Com]: Add logical combination assignment operators

From: Date: Tue, 04 Oct 2016 13:31:41 +0000
Subject: Req #49718 [Com]: Add logical combination assignment operators
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204441@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 Comment by: magnar at myrtveit dot com Reported by: robeddielee at hotmail dot com Summary: Add logical combination assignment operators Status: Open Type: Feature/Change Request Package: Scripting Engine problem Operating System: * PHP Version: * Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#204441) next »