3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo __FILE__; if (strlen(__FILE__) < 20) { copy(__FILE__, '/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php'); require_once '/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php'; return; } class Custom_StreamWrapper { public $context; public static function getPath($url, $mustExist = true) { $parts = explode('://', $url, 2); list($scheme, $path) = $parts; $path = stream_resolve_include_path($path); if (false === $path) { if ($mustExist) { throw new Exception('error'); } // centralize the stream_resolve_include_path logic return self::getPath(dirname($url)) .'/'. basename($url); } return $path; } public function stream_open($path, $mode, $options, &$openedPath) { // Modes 'a', 'c', 'w', 'x' are documented as: "If the file does not exist, attempt to create it" - so detect dir first and add filename if (in_array(substr($mode, 0, 1), array('a', 'c', 'w', 'x'))) $filepath = self::getPath($path, false); if (!isset($filepath)) $filepath = self::getPath($path); if ($options & STREAM_USE_PATH) $openedPath = $filepath; $this->_fp = fopen($filepath, $mode); return (bool)$this->_fp; } public function stream_write($data) { return fwrite($this->_fp, $data); } public function unlink($path) { return unlink(self::getPath($path)); } public function url_stat($path, $flags) { try { if ($flags & STREAM_URL_STAT_LINK) return lstat(self::getPath($path)); else return stat(self::getPath($path)); } catch (Exception $e) { if ($flags & STREAM_URL_STAT_QUIET) return false; throw $e; } } } if (!is_dir('/tmp/cache')) mkdir('/tmp/cache'); set_include_path('/tmp'); stream_wrapper_register('react', 'Custom_StreamWrapper'); file_exists('react://cache/react_unittest_filecache'); file_put_contents('react://cache/react_unittest_filecache', 'waa'); echo 'unlink'; unlink('react://cache/react_unittest_filecache'); file_exists('react://cache/react_unittest_filecache');
based on VSqQR
Output for 7.0.0 - 7.1.0
/in/YGJNG/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php Fatal error: Cannot declare class Custom_StreamWrapper, because the name is already in use in /tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php on line 12
Process exited with code 255.
Output for 5.2.0 - 5.4.35, 5.4.37 - 5.6.28
/in/YGJNG/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php Fatal error: Cannot redeclare class Custom_StreamWrapper in /tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php on line 13
Process exited with code 255.
Output for 5.4.36
/in/YGJNG Warning: require_once(/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php): failed to open stream: No such file or directory in /in/YGJNG on line 8 Fatal error: require_once(): Failed opening required '/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php' (include_path='.:') in /in/YGJNG on line 8
Process exited with code 255.
Output for 5.0.0 - 5.1.6
/in/YGJNG/tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php Fatal error: Cannot redeclare class custom_streamwrapper in /tmp/phpng_checkouts_somelongstring-2.0_cli_streamwrap.php on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/YGJNG on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/YGJNG on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/YGJNG on line 14
Process exited with code 255.