Skip to content

Improve error clarity when BindingResolutionException leads to “headers already sent” #56286

@MAboyadak

Description

@MAboyadak

Laravel Version

11

PHP Version

8.3

Database Driver & Version

No response

Description

When a class fails to resolve due to a typo or missing import (e.g., BindingResolutionException), Laravel attempts to render a 500 response. However, if output has already started (e.g., a PHP fatal error from Composer autoload), this results in a generic PHP error:

"Cannot modify header information - headers already sent by ... "

This masks the real root cause and makes debugging significantly harder.

Expected behavior:
Laravel should show the original exception that caused the failure — not just the secondary “headers already sent” error.

Steps To Reproduce

Example scenario:

define some valid route with some controller:

in controller:

use App\DTOs\Auth\GetUsersDTO; // incorrect namespace

This causes class autoload to fail -> fatal error is output -> Laravel tries to send a response -> PHP throws "headers already sent".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions