Archive

Archive for October, 2011

Sending Negative numbers through AMFPHP

October 28, 2011 Leave a comment

I wasted a whole monring with a weird bug. Some values sent from Flex to PHP throught AMFPHP ended up with values likes : 4294967209
After searching for a while, I found the solution here : amfphp forums

It’s a bug in AMFPHP, negative number are not converted correctly. It has to do with amfphp’s readAmf3Int() method in AMFDeserialzer.php. Here is the updated function that was posted on the forum:

function readAmf3Int()
{
$res = 0;

$int = $this->readByte();

if($int < 128)
return $int;
else
{
$int = ($int & 0x7f) <readByte();

if($tmp < 128)
{
$int |= $tmp;
}
else
{
$int = ($int | ($tmp & 0x7f)) <readByte();

if($tmp < 128)
{
$int |= $tmp;
}
else
{
$int = ($int | ($tmp & 0x7f)) <readByte();
$int |= $tmp;
}
}
}

$mask = 1<<28;

$res = -($int & $mask) | $int;

return $res;
}