Amfphp tries wherever possible to convert an AMF object to its PHP equivalent. However there are types where this equivalence doesn’t exist. In such cases you’ll have to use special Amfphp classes that you’ll find in Amfphp/Core/Types.
Note that you can’t return a PHP resource directly, you have to convert it to an array!
Here is a summary of the cases and types:
- Undefined. AMF has an Undefined type. There is however not such a type in PHP. So an AMF Undefined is converted to a Amfphp_Core_Amf_Types_Undefined, and you must use this same class to send back an Undefined.
- ByteArray. AMF has a ByteArray type. There is however not such a type in PHP. So an AMF ByteArray is converted to a Amfphp_Core_Amf_Types_ByteArray, and you must use this same class to send back an ByteArray.
- Date. AMF has a Date type, which contains a timestamp. PHP has a DateTime type, but it is for PHP 5.2 and more, and the timestamp functionality is for PHP 5.3 and more. So for the time being an AMF date is converted to and from an Amfphp_Core_Amf_Types_Date.
- XML. AMF has 2 XML types: XML and XMLDocument. PHP has many XML types and serializers and deserializers. So rather than to try to mix and match, the choice is left to the user. Amfphp will convert an AMF XML object to and from Amfphp_Core_Amf_Types_Xml, and a XMLDocument to and from Amfphp_Core_Amf_Types_XmlDocument. These classes both contain the XML data on the “data” property in string form, so the user can convert the data using whichever XML tools suits his purposes.
- Flex Array Collection. A Flex array collection is deserialized to an array. To return an array collection to Flex, use the following code:
$ret = new stdClass();
$explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
$ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
$ret->source = $yourData;