Details
Description
The class : Zend_Amf_Parse_Amf3_Serializer doesn't support cyclic references. (I didn't test the Zend_Amf_Parse_Amf0_Serializer).
Problem sample :
class ServiceProvider
{
/**
- @return TestObject
*/
public function testGetRecursiveObject() { $o = new TestObject(); $o->recursive = new TestObject(); $o->recursive->recursive = $o; return $o; }}
When you call testGetRecursiveObject() with an AMF request, the server doesn't respond. What is worse is that : on Win Vista the apache server stops running.
This problem is critical : no error is returned by the server.
The solution to solve this problem, is to use the "reference system" described in the AMF3 specifications.
I've tried to solve the problem myself but unfortunately without success : I think i didn't write the good code for writing the object reference on the output stream.
Here is the patch :
Index: Serializer.php
===================================================================
— Serializer.php (revision 14591)
+++ Serializer.php (working copy)
@@ -35,6 +35,8 @@
*/
class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
+ public function writeReference($object)
+ {
+ $this->_stream->writeByte(0x07);
+ $ref = & $object;
+ $ref = $ref << 1;
+ $this->writeInteger($ref);
+ }
+
+ private function referenceExist($object)
+ {
+ if(in_array($object, $this->_references, true)) {
+ return true;
+ } else {
+ $this->_references[] = $object;
+ return false;
+ }
+ }
+
/**
- Write object to ouput stream
*
@@ -258,6 +278,11 @@
*/
public function writeObject($object)
{
+ if($this->referenceExist($object)) { + $this->writeReference($object); + return $this; + }
+
$encoding = Zend_Amf_Constants::ET_PROPLIST;
$className = '';
This patch correct the problem