3v4l.org

run code in 300+ PHP versions simultaneously
<?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 */
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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) #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 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.32
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

preferences:
241.41 ms | 402 KiB | 319 Q