ZF-7587: Amf setClass() ignores pre-initialized objects and creates new objects


I need to set paramets into the __constructor of my PHP object before passing it off to Zend to use it as a Remote Procedure Call.

This works in Zend_Json but not in Zend_Amf. To do this with the Zend_JSON class I just create my object and pass it along as $this->server->setClass($object) and it will use that object in Zend/Server/Abstract.php method _displatch for $object = $invocable->getObject();

Instead the Zend_Amf_Server class overrides the Abstract _dispatch call and ignores the class I passed it. Instead it always calls $object = $info->getDeclaringClass()->newInstance();

Thus is creates a new instance and I am unable to use dependancy injection to establish my object.


i ran into the same problem as i use dependency injection for my objects too. I wrote a simple patch that solves this issue. Please have a look ...

the patch attached

Any ideas for a good way of writing a test case for this behavior?

yes, i'm going to write one or two unit tests ..

Ok. The patch is now more than one year old and sadly i hadn't the time to setup the full Zend Framework develpoment environment together with its unit tests to write another one for this use case.

But as the comments of the implemented Zend Server Interface state the setClass method behaves currently not as expected. Passing objects should be a valid option. I appreciate if we could commit this patch to trunk.

By the way i'll contribute another patch that fixes this behavior for Zend_Rest_Server too!