3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { private function customErrorHandler(int $code, string $msg): bool { var_dump(preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg)); return true; } protected function write(): void { set_error_handler([$this, 'customErrorHandler']); try { $stream = fopen('logs://userfrosting.log', 'a'); trigger_error('Test test'); } finally { restore_error_handler(); } } public function test() { $this->write(); } } class Bar { public function customErrorHandler(int $code, string $msg): bool { var_dump(preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg)); return true; } protected function write(): void { set_error_handler([$this, 'customErrorHandler']); try { $stream = fopen('logs://userfrosting.log', 'a'); trigger_error('Test test'); } finally { restore_error_handler(); } } public function test() { $this->write(); } } class StreamHandler { public $context; public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool { $path = str_replace('logs://', '', $path); return @fopen($path, $mode); } } stream_wrapper_register('logs', StreamHandler::class); (new Bar)->test(); (new Foo)->test();
Output for 8.5.1 - 8.5.3
string(44) "Failed to open stream: Read-only file system" string(63) "Failed to open stream: "StreamHandler::stream_open" call failed" string(9) "Test test" Fatal error: Uncaught Error: Invalid callback Foo::customErrorHandler, cannot access private method Foo::customErrorHandler() in /in/PjtpI:58 Stack trace: #0 /in/PjtpI(58): fopen('userfrosting.lo...', 'a') #1 [internal function]: StreamHandler->stream_open('userfrosting.lo...', 'a', 0, NULL) #2 /in/PjtpI(14): fopen('logs://userfros...', 'a') #3 /in/PjtpI(23): Foo->write() #4 /in/PjtpI(64): Foo->test() #5 {main} thrown in /in/PjtpI on line 58
Process exited with code 255.
Output for 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0
string(109) "open_basedir restriction in effect. File(userfrosting.log) is not within the allowed path(s): (/tmp:/in:/etc)" string(46) "Failed to open stream: Operation not permitted" string(63) "Failed to open stream: "StreamHandler::stream_open" call failed" string(9) "Test test" Fatal error: Uncaught Error: Invalid callback Foo::customErrorHandler, cannot access private method Foo::customErrorHandler() in /in/PjtpI:58 Stack trace: #0 /in/PjtpI(58): fopen('userfrosting.lo...', 'a') #1 [internal function]: StreamHandler->stream_open('userfrosting.lo...', 'a', 0, NULL) #2 /in/PjtpI(14): fopen('logs://userfros...', 'a') #3 /in/PjtpI(23): Foo->write() #4 /in/PjtpI(64): Foo->test() #5 {main} thrown in /in/PjtpI on line 58
Process exited with code 255.
Output for 8.1.0 - 8.1.34
string(109) "open_basedir restriction in effect. File(userfrosting.log) is not within the allowed path(s): (/tmp:/in:/etc)" string(46) "Failed to open stream: Operation not permitted" string(63) "Failed to open stream: "StreamHandler::stream_open" call failed" string(9) "Test test" string(63) "Failed to open stream: "StreamHandler::stream_open" call failed" string(9) "Test test"

preferences:
74.84 ms | 1052 KiB | 4 Q