stuartbates Posted September 17, 2010 Share Posted September 17, 2010 I've been looking through the Joomla docs trying to understand how everything works and I've seen something that I don't understand and cannot find an answer to anywhere on the net. The basic question is what is the ampersand used for in this conditional here: if (!($mask & 1) && is_string($var)) { The two in the middle are obviously the AND part of the conditional. I know it can be used for creating references to variables but I don't think this is what is happening here. I've seen people using it to test for odd and even numbers too but with no explanation of how it works/what it does. The full code is below: function _cleanVar($var, $mask = 0, $type=null) { // Static input filters for specific settings static $noHtmlFilter = null; static $safeHtmlFilter = null; // If the no trim flag is not set, trim the variable if (!($mask & 1) && is_string($var)) { $var = trim($var); } // Now we handle input filtering if ($mask & 2) { // If the allow raw flag is set, do not modify the variable $var = $var; } elseif ($mask & 4) { // If the allow html flag is set, apply a safe html filter to the variable if (is_null($safeHtmlFilter)) { $safeHtmlFilter = & JFilterInput::getInstance(null, null, 1, 1); } $var = $safeHtmlFilter->clean($var, $type); } else { // Since no allow flags were set, we will apply the most strict filter to the variable if (is_null($noHtmlFilter)) { $noHtmlFilter = & JFilterInput::getInstance(/* $tags, $attr, $tag_method, $attr_method, $xss_auto */); } $var = $noHtmlFilter->clean($var, $type); } return $var; } Quote Link to comment https://forums.phpfreaks.com/topic/213686-in-php-its-not-the-and-operator/ Share on other sites More sharing options...
taquitosensei Posted September 17, 2010 Share Posted September 17, 2010 It's a bitwise operator in this case. [/url]http://en.wikipedia.org/wiki/Bitwise_operation[/url] Quote Link to comment https://forums.phpfreaks.com/topic/213686-in-php-its-not-the-and-operator/#findComment-1112229 Share on other sites More sharing options...
stuartbates Posted September 17, 2010 Author Share Posted September 17, 2010 Thanks for the prompt reply I'd looked at those and disregarded them! Found an article that makes sense of it all for me now - so thanks again. In case anyone reads this and needs to know more http://www.litfuel.net/tutorials/bitwise.htm explains everything nicely Quote Link to comment https://forums.phpfreaks.com/topic/213686-in-php-its-not-the-and-operator/#findComment-1112239 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.