php-resque icon indicating copy to clipboard operation
php-resque copied to clipboard

Throwable PHP7

Open lon9man opened this issue 6 years ago • 5 comments

Expected Behavior

PHP7 needs to catch Throwable instead Exception

Current Behavior

try-catch don't catch Throwable instead Exception

Possible Solution

refactor all try-catch

My Environment

  • PHP-Resque version: latest
  • PHP version: 7.1
  • Operating System and version: Ubuntu 18.10

lon9man avatar Oct 14 '19 13:10 lon9man

No need to refactor all try/catch. PHP Resque Exceptions just have to implement Throwable interface.

BenoitDD-URIOS avatar Oct 14 '19 15:10 BenoitDD-URIOS

@Benoit-amo not sure that understood. for example: https://github.com/resque/php-resque/blob/fdca42bdb44197c6126d105daa4814fc5b5028ef/lib/Resque/Worker.php#L257

how this example can be refactored in other way than replacing Exception to Throwable?

lon9man avatar Oct 14 '19 16:10 lon9man

Ok, I missed that. How many catch like this ?

BenoitDD-URIOS avatar Oct 15 '19 07:10 BenoitDD-URIOS

@Benoit-amo with concrete "catch(Exception $e)" it seems only 1 occurence.

but exist some child-exceptions which has extended from Exception OR type-hinted parameters in methods: https://github.com/resque/php-resque/blob/fdca42bdb44197c6126d105daa4814fc5b5028ef/lib/Resque/Failure.php#L25 i am not sure which one should be updated to Throwable and which one not.

lon9man avatar Oct 15 '19 08:10 lon9man

There are a lot of PHP 7 updates that haven't been done yet. This one is relatively minor, as \Exception extends \Throwable anyway, so only \Errors will be uncaught, which is consistent with PHP 5 behavior. (AIUI, it's illegal to extend or even implement the \Throwable interface directly anyway, so only type hints should be updated even when we version bump to add this change.)

In other words, this will be a BC break, and will need several other PHP 7 changes in place before it makes any sense to do. So this will be an item on the PHP 7 checklist.

danhunsaker avatar Oct 20 '19 03:10 danhunsaker