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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 26 19:01:25 2019 UTC