3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface TemporaryFile { public function handle(\Closure $closure) : void; public function write(string $contents): void; public function getContents() : string; public function chmod(int $mode): void; public function getUri() : string; // aka realpath public function close() : void; } class IO { /** * @return TemporaryFile */ public static function getTemporaryFile() : TemporaryFile { return new class implements TemporaryFile { private $handle; public function __construct() { $this->handle = tmpfile(); } public function handle(\Closure $closure) : void { $closure($this->handle); } public function getContents() : string { // according to PHP docs file_get_contents has much better performance // http://php.net/manual/en/function.fread.php return file_get_contents($this->getUri()); } public function getUri() : string { return stream_get_meta_data($this->handle)['uri']; } public function close() : void { if (is_resource($this->handle)) fclose($this->handle); } public function write(string $contents): void { fwrite($this->handle, $contents); } public function chmod(int $mode): void { chmod($this->getUri(), $mode); } public function __destruct() { $this->close(); } }; } } $file = IO::getTemporaryFile(); $file->write('foo'); var_dump($file->getContents());
Output for git.master, git.master_jit, rfc.property-hooks
string(3) "foo"

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:
128.63 ms | 405 KiB | 5 Q