Skip to content

set_exception_handler() should be named set_throwable_handler() #17423

@adazmy

Description

@adazmy

Description

Both Error and Exception are handled by set_exception_handler() where the naming imply only the Exception.

A better explicit and intuitive name is set_throwable_handler().

I was not expecting the handler to be triggered by an Error and cancelling the default PHP behavior.

PS: not talking about E_XXX errors, but Error that implements Throwable

The following code:

<?php
function handler(){
     echo "Exception Handler";
}
set_exception_handler('handler');

new MyClass();

Resulted in this output:

Exception Handler

But I expected this output instead:

Fatal error: Uncaught Error: Class "MyClass" not found in /home/user/scripts/code.php:7
Stack trace:
#0 {main}
  thrown in /home/user/scripts/code.php on line 7

PHP Version

8.*

Operating System

No response

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