3v4l.org

run code in 300+ 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://foo.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://foo.log', 'a'); trigger_error('Test test'); } finally { restore_error_handler(); } } public function test() { $this->write(); } } class StreamHandler { public $context; protected $handle; public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool { $path = str_replace('logs://', '/tmp/', $path); $handle = @fopen($path, $mode); if ($handle === false) { return false; } $this->handle = $handle; return true; } } stream_wrapper_register('logs', StreamHandler::class); touch('/tmp/foo.log'); chmod('/tmp/foo.log', 0444); (new Bar)->test(); (new Foo)->test();
Output for git.master, git.master_jit, rfc.property-hooks
string(40) "Failed to open stream: Permission denied" 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/LsBph:59 Stack trace: #0 /in/LsBph(59): fopen('/tmp/foo.log', 'a') #1 [internal function]: StreamHandler->stream_open('/tmp/foo.log', 'a', 0, NULL) #2 /in/LsBph(14): fopen('logs://foo.log', 'a') #3 /in/LsBph(23): Foo->write() #4 /in/LsBph(75): Foo->test() #5 {main} thrown in /in/LsBph on line 59
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
25.72 ms | 406 KiB | 5 Q