3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $error_handler = function($level,$message) { echo "Main error handler: $message \n"; // ... // imagine somewhere inside the error handler a log writer is called // which uses it's own error handler for failing file operations // which is what Zend\Log\Writer\Stream does with Zend\StdLib\ErrorHandler $nested_error_handler = function ($level,$message) { echo "Nested error handler: $message \n"; }; set_error_handler($nested_error_handler,E_WARNING); //strpos(); //Produce a warning inside the log writer restore_error_handler(); //restore the error handler to $eh after log written // ... set_error_handler($this); return true; }; set_error_handler($error_handler); trigger_error('Some message',E_USER_NOTICE); /* expected output: Main error handler: Some message */ trigger_error('Some other message',E_USER_NOTICE); /* expected output: Main error handler: Some other message */
based on UiOMA
Output for 7.1.0 - 7.2.0
Main error handler: Some message Fatal error: Uncaught Error: Using $this when not in object context in /in/5UstZ:16 Stack trace: #0 [internal function]: {closure}(1024, 'Some message', '/in/5UstZ', 23, Array) #1 /in/5UstZ(23): trigger_error('Some message', 1024) #2 {main} thrown in /in/5UstZ on line 16
Process exited with code 255.
Output for 5.5.24 - 7.0.20
Main error handler: Some message Notice: Undefined variable: this in /in/5UstZ on line 16 Notice: Some other message in /in/5UstZ on line 27
Output for 5.3.21 - 5.4.45
Main error handler: Some message Notice: Undefined variable: this in /in/5UstZ on line 16 Warning: set_error_handler() expects the argument () to be a valid callback in /in/5UstZ on line 16 Notice: Some other message in /in/5UstZ on line 27