Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Throwable vs. Exception #146

Closed
PhoneBuster opened this issue Jun 1, 2016 · 7 comments
Closed

Throwable vs. Exception #146

PhoneBuster opened this issue Jun 1, 2016 · 7 comments

Comments

@PhoneBuster
Copy link

PhoneBuster commented Jun 1, 2016

I use zend-mvc 2.7.8. If i have a bad argument in my own factory the framework throws the following error :

Fatal error: Uncaught TypeError: Argument 4 passed to Zend\Mvc\DispatchListener::marshalBadControllerEvent() must be an instance of Exception, instance of TypeError given...

To fix this i've to change the the argument type in the DispatchListener class (method marshalBadControllerEvent) from

   protected function marshalBadControllerEvent(
        $controllerName,
        MvcEvent $event,
        Application $application,
        \Exception $exception
    ) {
        $event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
        $event->setError($application::ERROR_EXCEPTION);
        $event->setController($controllerName);
        $event->setParam('exception', $exception);

        $events  = $application->getEventManager();
        $results = $events->triggerEvent($event);
        $return  = $results->last();
        if (! $return) {
            return $event->getResult();
        }

        return $return;
    }

to

   protected function marshalBadControllerEvent(
        $controllerName,
        MvcEvent $event,
        Application $application,
        Throwable $exception
    ) {
        $event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
        $event->setError($application::ERROR_EXCEPTION);
        $event->setController($controllerName);
        $event->setParam('exception', $exception);

        $events  = $application->getEventManager();
        $results = $events->triggerEvent($event);
        $return  = $results->last();
        if (! $return) {
            return $event->getResult();
        }

        return $return;
    }
@Ocramius
Copy link
Member

Ocramius commented Jun 1, 2016

Due to PHP 5.x compatibility, the quickest solution for now is to drop the type-hint completely

@PhoneBuster
Copy link
Author

My PHP Version is 7

@Ocramius
Copy link
Member

Ocramius commented Jun 1, 2016

The library still supports some versions of PHP 5.x

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

On 1 June 2016 at 15:58, PhoneBuster notifications@github.com wrote:

My PHP Version is 7


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#146 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAJakNH_UrdaiMsQrDm9K4u--IUObNO7ks5qHZAcgaJpZM4Irijo
.

@weierophinney
Copy link
Member

Fixed with #153 and release 2.7.9. You may also need to update your error templates per the suggestions in #157.

@andreaventuri
Copy link

I still have the same problem in version 3.0.1

@michalbundyra
Copy link
Member

It was fixed only on v2.7, here you have issue for v3: #161

/cc @weierophinney

@weierophinney
Copy link
Member

Fixed with #161.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants