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. ariels

    19 Mai 11

    thanks 🙂

  2. erikmoreno

    27 Avr 12

    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

  3. ariels

    27 Avr 12

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

  4. Deleu

    15 Fév 13

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

Laissez un commentaire

News letter

Evénements Silex Labs sur Paris et sa région: Inscrivez vous à la Newsletter mensuelle

Silex Labs community Tweets

Facebook page