Here are my tweaks to amfphp for sending an ArrayCollection from Flex to amfphp. May not be the cleanest or most proper but it works. From what I understand, there is an ArrayCollection class included in Zend_AMF, but I haven't looked into that.

I've been sending ArrayCollections from php to Flex for a while, it's pretty simple and info for doing that can be found at Wade Arnold's blog here. The issue going the other direction is that Flex only sends the AC's underlying source array when serializing it for amf. So when amfphp unpacks the data, you're dealing with a normal array.

Obviously, the first thing you'll need is your ArrayCollection class to use (I use the version that extends ArrayObject at the link above), and make sure it is in your include path.

The first tweak to amfphp is to the method AMFBaseDeserializer->mapClass(). In that method, right after the checks looking for CommandMessage and RemotingMessage types, I added a similar check for ArrayCollection:

PHP:
  1. if($typeIdentifier == "flex.messaging.io.ArrayCollection")
  2. {
  3.         return new ArrayCollection();
  4. }

Next change is to the AMFDeserializer->readAmf3Object() method. Near the middle of the method, around line 570, there is a check for ArrayCollection, and if found it will call the readAmf3Data() method. I changed it to pass in a value of "true" to the method, you'll see why in a sec:

PHP:
  1. if( $classDefinition['externalizable'] )
  2. {
  3.     if($type == 'flex.messaging.io.ArrayCollection')
  4.     {
  5.         $obj = $this->readAmf3Data(true);
  6.     }

Now just two small tweaks to the readAmf3Data() method. I changed the method signature to add an $isArrayCollection parameter, which just gets forwarded on when calling readAmf3Array. Here's the whole method:

PHP:
  1. function readAmf3Data($isArrayCollection = false)
  2. {
  3.     $type = $this->readByte();
  4.    
  5.     switch($type)
  6.     {
  7.         case 0x00 : return null; //undefined
  8.         case 0x01 : return null; //null
  9.         case 0x02 : return false; //boolean false
  10.         case 0x03 : return true//boolean true
  11.         case 0x04 : return $this->readAmf3Int();
  12.         case 0x05 : return $this->readDouble();
  13.         case 0x06 : return $this->readAmf3String();
  14.         case 0x07 : return $this->readAmf3XmlString();
  15.         case 0x08 : return $this->readAmf3Date();
  16.         case 0x09 : return $this->readAmf3Array($isArrayCollection);
  17.         case 0x0A : return $this->readAmf3Object();
  18.         case 0x0B : return $this->readAmf3XmlString();
  19.         case 0x0C : return $this->readAmf3ByteArray();
  20.         default: trigger_error("undefined Amf3 type encountered: " . $type, E_USER_ERROR);
  21.     }
  22. }

Now just another two small tweaks to the readAmf3Array method. As with the readAmf3Data() method, we add the $isArrayCollection parameter. Within the body of the method, I just check if that param is true when creating the $hashtable variable, and if it is, use an ArrayCollection instead of a regular array:

PHP:
  1. function readAmf3Array($isArrayCollection = false)
  2. {
  3.     $handle = $this->readAmf3Int();
  4.     $inline = (($handle & 1)  != 0 ); $handle = $handle>> 1;
  5.  
  6.     if( $inline )
  7.     {
  8.         $hashtable = $isArrayCollection ? new ArrayCollection() : array();
  9.        
  10.         $this->storedObjects[] = & $hashtable;
  11.         $key = $this->readAmf3String();
  12.         while( $key != "" )
  13.         {
  14.             $value = $this->readAmf3Data();
  15.             $hashtable[$key] = $value;
  16.             $key = $this->readAmf3String();
  17.         }
  18.  
  19.         for($i = 0; $i <$handle; $i++)
  20.         {
  21.             //Grab the type for each element.
  22.             $value = $this->readAmf3Data();
  23.             $hashtable[$i] = $value;
  24.         }
  25.         return $hashtable;
  26.     }
  27.     else
  28.     {
  29.         return $this->storedObjects[$handle];
  30.     }
  31. }

That's it. Now I can send the an AC to the server, serialize it, unserialize it and send it back to Flex with no issues. The one thing that may an issue is if one of the items within an AC is also another AC...haven't checked out if that works yet.