From: php at richardneill dot org Operating system: PHP version: 6CVS-2008-10-06 (CVS) PHP Bug Type: Feature/Change Request Bug description: wish: compound logical operators (nand, xor, etc)
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. -- Edit bug report at http://bugs.php.net/?id=46239&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46239&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46239&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46239&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46239&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46239&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46239&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46239&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46239&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46239&r=support Expected behavior: http://bugs.php.net/fix.php?id=46239&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46239&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46239&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46239&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46239&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46239&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46239&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46239&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46239&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46239&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46239&r=mysqlcfg