set_error_handler

Supported Versions: PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8
Sets a user-defined error handler function
set_error_handler(?callable $callbackint $error_levels E_ALL): ?callable
        error_reporting(-1);



        
set_error_handler($this->forwardsTo('handleError'));



        
set_exception_handler($this->forwardsTo('handleException'));
    protected function withDeprecationHandling()

    {

        if (
$this->originalDeprecationHandler) {

            
set_error_handler(tap($this->originalDeprecationHandler, function () {

                
$this->originalDeprecationHandler null;

            }));

        }



        return 
$this;
    protected function withoutDeprecationHandling()

    {

        if (
$this->originalDeprecationHandler == null) {

            
$this->originalDeprecationHandler set_error_handler(function ($level$message$file ''$line 0) {

                if (
in_array($level, [E_DEPRECATEDE_USER_DEPRECATED]) || (error_reporting() & $level)) {

                    throw new 
ErrorException($message0$level$file$line);

                }

            });

        }



        return 
$this;
    {

        
parent::setUp();



        
$this->original set_error_handler(function () {

            
$this->deprecationsFound true;

        });

    }



    public function 
testWithDeprecationHandling()
    protected function tearDown(): void

    
{

        
set_error_handler($this->original);



        
$this->originalDeprecationHandler null;

        
$this->deprecationsFound false;