php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72266 AND and OR combined operators
Submitted: 2016-05-26 11:15 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: remyfox at hotmail dot com Assigned:
Status: Open Package: Variables related
PHP Version: Irrelevant OS: Any
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: remyfox at hotmail dot com
New email:
PHP Version: OS:

 

 [2016-05-26 11:15 UTC] remyfox at hotmail dot com
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();
}


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-14 12:55 UTC] tolsen at southern dot edu
The following pull request has been associated:

Patch Name: Added request #72266
On GitHub:  https://github.com/php/php-src/pull/4535
Patch:      https://github.com/php/php-src/pull/4535.patch
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Nov 15 13:01:35 2019 UTC