PDA

View Full Version : What does this symbol do?


vBNinja
03-31-2013, 11:33 PM
if ($vbulletin->userinfo['userid'] > 0 AND ($vbulletin->userinfo['permissions']['forumpermissions'] & $vbulletin->bf_ugp_forumpermissions['custom_perm']))


I understand all of it but the "&" symbol in the middle. Im not sure if it's supposed to be "&&" or if it's trying to use references. But there's no equal sign so it can't be a reference. Does anyone know what it's supposed to be?

Thanks

kh99
03-31-2013, 11:51 PM
It's the bitwise AND operator: http://php.net/manual/en/language.operators.bitwise.php. $vbulletin->userinfo['permissions']['forumpermissions'] is a number which, when you look at it as a binary value, each bit is the state of one forum permission for that user. $vbulletin->bf_ugp_forumpermissions['custom_perm'] is a "mask" value with only one bit set, the bit corresponding to the "custom_perm" permission (whatever that is). So if you "bitwise AND" those two values, the result will be either 0 or non-zero, depending on whether or not the user has that permission.

Probably that's either too much or not enough of an explanation. If it's not enough, this might help: http://en.wikipedia.org/wiki/Bitmask

vBNinja
04-01-2013, 02:07 PM
Ahh it's pretty confusing but i think i got an idea of what it does, thanks!

nhawk
04-01-2013, 04:31 PM
Just to confuse you a little more :D ...

A double ampersand "&&" is the same as AND in that code. So it could also appear as this..

if ($vbulletin->userinfo['userid'] > 0 && ($vbulletin->userinfo['permissions']['forumpermissions'] & $vbulletin->bf_ugp_forumpermissions['custom_perm']))

vBNinja
04-01-2013, 05:00 PM
Just to confuse you a little more :D ...

A double ampersand "&&" is the same as AND in that code. So it could also appear as this..

if ($vbulletin->userinfo['userid'] > 0 && ($vbulletin->userinfo['permissions']['forumpermissions'] & $vbulletin->bf_ugp_forumpermissions['custom_perm']))


Yea i know that "&&" and "AND" are the same thing :P