The result of imagetypes() is a bitset, and & is the bitwise operator AND. The condition is expressing 'if the imagetypes() bitset has the IMG_GIF bit set', relying on PHP's interpretation of 0 as false.
For example, if we (probably inaccurately; it doesn't matter for the purposes of demonstration) let IMG_PNG = 1, IMG_GIF = 2, IMG_JPEG = 4, then 7 (1 + 2 + 4) expresses all three:
Code:
$imagetypes = 1 + 2 + 4;
// 1bin + 10bin + 100bin = 111bin = 7dec
$imagetypes & IMG_GIF;
// 111
// & 010
// = 010
$imagetypes = 1 + 4;
// remove GIF support
// 1bin + 100bin = 101bin = 5dec
// we could also express this as $imagetypes -= 2
// or $imagetypes ^= 2 (^ is XOR)
// where the operands are composed only of powers of two,
// OR is equivalent to +, and XOR to -, but with a lower
// bound of 0.
$imagetypes & IMG_GIF;
// 101
// & 010
// = 000
Bookmarks