cphalcon: [NFR][PHP 7]beforeThrowable, beforeError in dispatcher

In php 7 there was added Throwable interface. We need to in dispatcher and micro, add option to catch throwable(so errors too). Im thinking how to do this exactly, there is my idea:

  • just add new event beforeThrowable and catch all Throwable, if there is some handler attached to this event then use it
  • if there is no handler attached to this event then if it’s exception we will just pass it to beforeException, so current code will keep working but throw errors only
  • add beforeError event to catch only errors - so we don’t need to change any code we have currently with beforeException and we can add code to catch Error only

So in result no code changes will be needed if we don’t care about errors in php 7 or our application will not produce them. If we want add support for it we can either switch beforeException to beforeThrowable with current code or just add new attach for beforeError with new handler for it.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 27 (27 by maintainers)

Most upvoted comments

function(Event $event, Dispatcher $dispatcer, Throwable $throwable) {

you will just not add this for php 5 anway because Throwable don’t exist in php 5

} catch \Throwable, e {

Well, it’s not my problem if zephir don’t support this. Just in php you can do catch Throwable in php5, it will work without any problem

These checks to handle instanceof should be done in application land … not core land. I have benchmarks since I’ve already rewritten the dispatcher in my current branch because your latest updates to dispatcher have broken in on 3.x PHP5.6

You can still handle errors manually Jurigag. Changing the framework will break backwards compatibility. This should be implemented in dispatcher as well as across the board for all pieces of code when Phalcon goes minimum of PHP7. I’m not sure what milestone this will be … maybe a year out or so with v4 or v5.

Right now… you can simply catch (Throwable $t) in your application code.

But 4.0 will be like in few years and for now this means we don’t have way to handle errors in framework, otherwise than set_error_handler in php.