Zend\Json\Server\Server::addFunction instantiates new class even an object was given as callable #4604

Closed
oliverwelter opened this Issue Jun 7, 2013 · 1 comment

Projects

None yet

2 participants

@oliverwelter

Zend\Json\Server\Server::addFunction instantiates a new object even if an object is given as a callable.
e.g.
$server->addFunction(array($this, 'remoteProcedure'));

This gets problematic in case the constructor has arguments or the object needs further initialisation.
In contrast to this Zend\Json\Server\Server::setClass reuses the given object.

The behaviour is caused by the difference in the call to
Zend\Server\AbstractServer::_buildSignature

setClass:
$definition = $this->_buildSignature($method, $class); (line 133)

addFunction:
$definition = $this->_buildSignature($method); (line 109)

If there are no reasons against it the fix would be
using
$definition = $this->_buildSignature($method, $class);
as well in addFunction.

@steverhoades
Contributor

@sephritoth Please reference #5379 for fix.

@gianarb gianarb pushed a commit to zendframework/zend-json that referenced this issue May 15, 2015
@steverhoades steverhoades fixes zendframework/zendframework#4604 - if class contains constructo…
…r addFunction will no longer result in an error.
bf00414
@weierophinney weierophinney added a commit to zendframework/zend-json that referenced this issue May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5379 from steverhoades…
…/hotfix/4604

fixes zendframework/zendframework#4604
6c7b1b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment