|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-09-26 21:24 UTC] cmb@php.net
-Status: Open
+Status: Suspended
-Package: Feature/Change Request
+Package: *General Issues
[2017-09-26 21:24 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 11:00:01 2025 UTC |
Description: ------------ This is a request for a new set of functions, namely the more complex logical operations, NAND, NOR, XOR, XNOR etc. I suggest implementing them as functions, rather than as operators, because they can take a variable number of arguments. These would also be distinct from the bitwise operators. Of course these are pretty trivial to implement oneself as and when needed, but it would make a small increment of improvement to PHP ;-) The other advantage is in code-readability. I think that example1 is more readable than example2: $example1 = nand ($condition_1, $condition_2, $condition_3, $condition_4) $example2 = (! ($condition_1 and $condition_2 and $condition3 and $condition_4) Thanks for your time and consideration - Richard Reproduce code: --------------- A possible implementation: function nand($a,$b,$c,....){ #cast everything to boolean return !($a and $b and $c ...); } function nor($a,$b,$c,...){ #cast to boolean return !($a or $b or $c or ...); } function new_and($a,$b,$c,...){ #note: this makes the syntax much clearer and shorter if #there are very many inputs. return ($a and $b and $c...); } #similarly, new_or() function xor($a,$b,$c,...){ $count=0; if ($a){ $count++ ;} if ($b){ $count++ ;} if ($c){ $count++ ;} ... return ($count == 1); } function xnor($a,$b,$c,...){ $count=0; if ($a){ $count++ ;} if ($b){ $count++ ;} if ($c){ $count++ ;} ... return ($count != 1); } function majority($a,$b,$c,...){ $count=0; if ($a){ $count++ ;} if ($b){ $count++ ;} if ($c){ $count++ ;} .. return ($count > $number_of_args/2); } #and any others I've missed out.