AMF Data Types

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 = "";
    $ret->source = $yourData;
    return $ret;


  1. Profile photo of erikmoreno


    April 27, 2012

    Se me hace extraño que digan que AmfPHP no soporta el envio de un ArrayCollection al Cliente. Por ejemplo, yo lo he hecho con Flex. Tengo una clase en php llamada ArrayCollection, con una variable $_explicitType = “”, tiene varios de los métodos que se usan. Flex lo recibe sin ningun problema como un ArrayCollection

    • Profile photo of Ariel Sommeria-Klein

      Ariel Sommeria-Klein

      April 27, 2012

      like the doc says: AmfPHP does not however support sending an ArrayCollection to the client.

  2. Profile photo of Deleu


    February 15, 2013

    But Amfphp sends back an Array which you can pass as constructor to the ArrayCollection and voalà

Add a comment


This content
is outdated.

Discover Silex v2,
online website builder.

Sign up for Silex Labs news by email

SilexLabs community Tweets