Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root exception class (and possibly, its children) not compatible with PHP7+ #325

Open
uuf6429 opened this issue Sep 7, 2022 · 0 comments

Comments

@uuf6429
Copy link

uuf6429 commented Sep 7, 2022

\Exception $previous = null,

This breaks on PHP 7+ when a non-\Exception throwable is thrown (e.g. TypeError; see also the type hierarchy).

For best compatibility, the type declaration should be removed. If needs be, ?\Exception / ?\Throwable could be defined via PHPDoc.

Since it's removing a restriction, I don't think this should be considered as a BC break.


On a side note, not sure why it needs to keep a copy of the message:

protected $message;

and
$this->message = $message;


An effective stopgap solution for my use-case:

class InternalServerErrorException extends \League\Route\Http\Exception
{
    protected $status = 500;
    protected $message = 'Internal Server Error';

    /**
     * @throws \ReflectionException
     * @noinspection MagicMethodsValidityInspection
     * @noinspection PhpMissingParentConstructorInspection
     */
    public function __construct(Throwable $previous = null)
    {
        $reflector = new \ReflectionMethod(\Exception::class, '__construct');
        $reflector->invoke($this, $this->message, 0, $previous);
    }
}
@uuf6429 uuf6429 changed the title Root exception class not compatible with PHP7+ Root exception class (and possibly, its children) not compatible with PHP7+ Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant