Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trevorpan's avatar

renderForConsole($output, Throwable $exception) upgrade guide differs from api

https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades

use Throwable;

public function renderForConsole($output, Throwable $exception);

https://laravel.com/api/7.x/Illuminate/Contracts/Debug/ExceptionHandler.html#method_renderForConsole

void renderForConsole(OutputInterface $output, Throwable $e)

I'm trying to make a custom console exception work and noticed the docs don't fully line up. When I tried making the renderForConsole(OutputInterface $output, Throwable $e) like the api, phpstorm gave an error: method must be compatible with ExceptionHandler->renderForConsole etc.

Is it common for these to not exactly match? Or is the OutputInterface used by Throwable? I searched that file but could not see a reference.

0 likes
5 replies
bobbybouwmann's avatar
Level 88

So the problem here is that you type-hint OutputInterface here, while the code in Laravel Framework does not do this. Because of that, they seem to be incompatible.

So the docs are correct about the type because the docblocks are implemented correctly.

/**
 * Render an exception to the console.
 *
 * @param  \Symfony\Component\Console\Output\OutputInterface  $output
 * @param  \Throwable  $e
 * @return void
 */
public function renderForConsole($output, Throwable $e);

So if this was type-hinted as well, you wouldn't have this issue.

Let me know if this makes sense to you ;)

trevorpan's avatar

Ok, so the doc block essentially visually "cleans up" the method in the () but calls the same interface?

In my particular file there are no doc blocks and they are not suggested by phpstorm for some reason.

Just trying to understand why the docs say public function renderForConsole($output, Throwable $exception); exception is fully spelled out but the api states $e or does it even matter?

Not that you would - but could it be Throwable $z and still work?

bobbybouwmann's avatar

@trevorpan The thing is that the type hinting needs to match with the parent method. I believe you can change the variable names if you wish.

In this case, the parent method provided by Laravle only type-hints Throwable, so that on is required. The OutputInterface is not type-hinted, so if you add it to your method it doesn't match with the parent anymore and it fails.

If you add the type-hint, you're saying the same as the docblock but than the inheritance doesn't match anymore. It would be better if Laravel would type-hint the OutputInterface interface here as well in the end. However, that is a breaking change.

trevorpan's avatar

@bobbybouwmann

Well - for sure this new tool I picked up Larastan is causing me to look more at this level of detail. Just an excellent leveling up - still think I'll need another year or so to really get it.

As always thank you!

Where's my laravel secrets? You know I'm waiting for that to become available!!

bobbybouwmann's avatar

@trevorpan Still working on Laravel Secrets. Corona didn't help out here ;) It's coming this year!

I also use Larastan in all my projects and it really helps to get stuff to the next level ;) Keep up the good work

Please or to participate in this conversation.