I was going to use a long string to manipulate a large number of bit flags, keeping the result string in Redis. However, stumbled upon a php bug (?). A byte that contains bits 00001101
read using substr()
returns an unexpected value:
$bin = 0b00001101; // 13 - ASCII Carriage return
$c = substr($bin, 0, 1); // read this character
printf("Expectation: 00001101, reality: %08b\n", $c); // 00000001
Is the assumption that substr()
is binary-safe wrong? Also tried mb_substr()
, setting encoding to 8bit
with exactly the same result.