silexlabs/amfphp-2.0 — Issue #7: AMF version detection missing in amf Deserializer
Author: raweden
Created: 2011-11-22 19:21:09+00:00
State: open

There is implementation bug in the deserializer which also affects the AMF serialization. The version used is not detected properly so the serializer won't encode the ByteArray as a AMF3 ByteArray. I think i also have solved most of the problem, but it's up to u to implement it.
```
protected function readHeaders() {
$topByte = $this->readByte(); // ignore the first two bytes -- version or something
$secondByte = $this->readByte(); //0 for Flash,

// This line i would think solves the version detection problem. The value value bellow will return 3 for AMF3 and null for AMF0
$version = ($topByte & 0xFF) << 8 | $secondByte & 0xFF;
$this->deserializedPacket->amfVersion = $version == 3 ? AMFConstants::AMF3_ENCODING : AMFConstants::AMF3_ENCODING;
```
as mentioned above the version code above should detect which version of amf that is used, its mentioned in the AMF0 format specification that the first two bytes (unsigned 16-bit int) stands for the version.