Req #72266 [NEW]: AND and OR combined operators
| From: | remyfox at hotmail dot com | Date: | Thu, 26 May 2016 11:15:39 +0000 |
| Subject: | Req #72266 [NEW]: AND and OR combined operators | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-201281@lists.php.net to get a copy of this message | ||
From: remyfox at hotmail dot com
Operating system: Any
PHP version: Irrelevant
Package: Variables related
Bug Type: Feature/Change Request
Bug description:AND and OR combined operators
Description:
------------
From the manual
http://php.net/manual/en/language.operators.assignment.php:
there are
"combined operators" for all of the binary arithmetic, array union and
string operators that allow you to use a value in an expression and then
set its value to the result of that expression.
Wouldn't it be better to allow combined operations for all binary
operators? It seems arbitrary that some binary operators (such as the
logical ones) don't support this. There seem to be plenty of use cases.
Test script:
---------------
// In a system where a user obtains a permission if he has at least one
role that gives such a permission.
$permitted = false;
foreach ($user_roles as $user_role) {
$permitted ||= $user_role["permitted"];
}
// In a system where multiple validations exists which each return a
boolean.
$valid = true;
foreach ($validations as $validation) {
$valid &&= $validation();
}
--
Edit bug report at https://bugs.php.net/bug.php?id=72266&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72266&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72266&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72266&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72266&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72266&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72266&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72266&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72266&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72266&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72266&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72266&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72266&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72266&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72266&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72266&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72266&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72266&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72266&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72266&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72266&r=mysqlcfg