See https://github.com/silexlabs/amfphp-2.0/blob/master/Amfphp/Core/Amf/Serializer.php line 329 to 336. you write the number of objects, then each object.
additional question: same code, look for Amf0StoredObjects. references ids are only for referencable objects. These vary for AMF0 and AMF3 though.