3v4l.org

run code in 500+ PHP versions simultaneously
<?php namespace Foo; class StreamHandler { public $errorMessage; public function __construct() { $this->errorMessage = null; set_error_handler([$this, 'customErrorHandler']); $stream = fopen('c:/fososdfsdfsd', 'a'); restore_error_handler(); } private function customErrorHandler(int $code, string $msg): bool { $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg); return true; } } function fopen() { throw new \Exception(); } try{ $f = new StreamHandler; var_dump($f->errorMessage); }catch (\Throwable){ } $a = []; var_dump($a[1]);
Output for 8.2.0 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
Fatal error: Uncaught Error: Invalid callback Foo\StreamHandler::customErrorHandler, cannot access private method Foo\StreamHandler::customErrorHandler() in /in/e3L7U:37 Stack trace: #0 {main} thrown in /in/e3L7U on line 37
Process exited with code 255.
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34
Warning: Invalid callback Foo\StreamHandler::customErrorHandler, cannot access private method Foo\StreamHandler::customErrorHandler() in /in/e3L7U on line 37 Warning: Undefined array key 1 in /in/e3L7U on line 37 NULL

preferences:
83.85 ms | 1162 KiB | 4 Q