Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Zend\Mvc\Application::run returns ResponseInterface. #4831

wants to merge 1 commit into from

3 participants

reenl Maks3w Matthew Weier O'Phinney

This fixes a bug where the run function returns a \Zend\Mvc\Application in a lot of cases. According to the phpdoc and the documentation it should return a Zend\Stdlib\ResponseInterface.


Agree but due a potential BC Break I suggest apply it in the next major version


e2d8c14 and 643a99e where BC breaks, this restores the error somewhat.

At the moment the return value of ::run is unusable because you can't know for sure what is returned (note that it still returns the ResponseInterface in some cases before my PR). BC break or not, this is a bug and should be fixed.

The documentation should be updated too, whatever fix we do because this is simply not true no matter how we choose to fix it:

$application = $serviceManager->get('Application');
$response = $application->run();

Because a response doesn't have a send method, and the application does not return a response. And depending the routes / application environment this could be a fatal error.

Either we choose to always return Application or ResponseInterface. I can of course send this PR to develop if you wish.

If you tell me your wishes, I can make the changes.

Matthew Weier O'Phinney

It's a documentation issue at this point. We modified how Zend\Mvc\Application works, as there were issues with simply rendering the response (if you are doing a stream, for instance, an echo was a bad idea). So, the run() method's signature should be updated, and documentation updated. We already updated the skeleton application some time ago, and messaged the change when it was released.


Note that it still returns a resonseinterface in some cases.

reenl reenl deleted the branch
Matthew Weier O'Phinney

@reenl I'll correct hose; they're legacy at best, and the method should be consistent.

Matthew Weier O'Phinney weierophinney referenced this pull request from a commit in weierophinney/zf2
Matthew Weier O'Phinney weierophinney [#4831] Fix run() return values
- Always return the application instance. (and fix docblock to indicate this)
- If an alternate response object is returned by an event, give it to
  the application instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2013
  1. reenl
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 4 deletions.
  1. +4 −4 library/Zend/Mvc/Application.php
8 library/Zend/Mvc/Application.php
@@ -297,12 +297,13 @@ public function run()
return $response;
if ($event->getError()) {
- return $this->completeRequest($event);
+ $this->completeRequest($event);
return $event->getResponse();
if ($event->getError()) {
- return $this->completeRequest($event);
+ $this->completeRequest($event);
+ return $event->getResponse();
// Trigger dispatch event
@@ -320,8 +321,7 @@ public function run()
$response = $this->getResponse();
- return $this;
+ return $response;
Something went wrong with that request. Please try again.