3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ClosureHash { /** * List of hashes * * @var SplObjectStorage */ protected static $hashes = null; /** * Returns a hash for closure * * @param callable $closure * * @return string */ public static function from(Closure $closure) { if (!self::$hashes) { self::$hashes = new SplObjectStorage(); } if (!isset(self::$hashes[$closure])) { $ref = new ReflectionFunction($closure); $file = new SplFileObject($ref->getFileName()); $file->seek($ref->getStartLine()-1); $content = ''; while ($file->key() < $ref->getEndLine()) { $content .= $file->current(); $file->next(); } self::$hashes[$closure] = md5(json_encode(array( $content, $ref->getStaticVariables() ))); } return self::$hashes[$closure]; } } class Test { public function hello($greeting) { $closure = function ($message) use ($greeting, &$closure) { echo "Inside: ", ClosureHash::from($closure), PHP_EOL, "<br>" ; }; return $closure; } } $obj = new Test(); $closure = $obj->hello('Hello'); $closure('PHP'); echo "Outside: ", ClosureHash::from($closure), PHP_EOL, "<br>"; $another = $obj->hello('Bonjour'); $another('PHP'); echo "Outside: ", ClosureHash::from($another), PHP_EOL, "<br>";
Output for git.master, git.master_jit, rfc.property-hooks
Inside: 3f3fbdf1b2226ff3eb08f8e8f6dd1d87 <br>Outside: 3f3fbdf1b2226ff3eb08f8e8f6dd1d87 <br>Inside: 5b5ecac84caac9f40efe587b26de92df <br>Outside: 5b5ecac84caac9f40efe587b26de92df <br>

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:
32.29 ms | 401 KiB | 8 Q