facebook/hiphop-php — Issue #432: array_map as function parsing failure with binary packed strings.
Author: pedigree
Created: 2011-11-21 23:11:36+00:00
State: open

This showed due to random issues with a redis client, which works perfectly in PHP itself

Using function and vars

define('CRLF', sprintf('%s%s', chr(13), chr(10)));
function bintohex($str) {
$hex = ""; $i = 0; do {
$hex .= sprintf("%02x", ord($str{$i})); $i++;
} while ($i < strlen($str));
return $hex;
}
$args[0] = "\x00\x5f";
$args[1] = "\x81\x77\x97\xa1\x8d\x4a\x25\xc1\x83\x71\xa0\x50\x02\xb7";
$name = 'hset';

this is the code that produces different output in HipHop and PHP

array_unshift($args, strtoupper($name));
$command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(function($arg) {
return sprintf('$%d%s%s', strlen($arg), CRLF, $arg);
}, $args), CRLF), CRLF);
print "command = " . bintohex($command);

In PHP you get the correct output of

2a330d0a24340d0a484745540d0a24320d0a005f0d0a2431340d0a817797a18d4a25c18371a05002b70d0a

In HipHop, you get an incorrect hexdump as it has missed the binary \x00\x5F $args[0] in the pass back and passes back an empty string so that you end up with 0d0a0d0a instead of 0d0a005f0d0a

2a330d0a24340d0a484745540d0a24320d0a0d0a2431340d0a817797a18d4a25c18371a05002b70d0a