3v4l.org

run code in 300+ PHP versions simultaneously
<?php function e($n,$p,$c=0){static $a;@krsort($a[$n]);if($c)$a[$n][$p][]=$c;else foreach($a[$n] as$q)foreach($q as$r)$r($p);} function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);} ob_start(); e( 'event', 0, function ($data) { echo "event, $data, priority 0;"; } ); e( 'event', 10, function ($data) { echo "event, $data, priority 10;"; } ); e( 'other_event', -5, function ($data) { echo "other_event, $data, priority -5;"; } ); e( 'other_event', 5, function ($data) { echo "other_event, $data priority 5;"; } ); e('event', 'dataX'); e('other_event', 'dataY'); $output = ob_get_contents(); ob_end_clean(); it( 'calls event listeners in the right order', $output === 'event, dataX, priority 10;event, dataX, priority 0;other_event, dataY priority 5;other_event, dataY, priority -5;' ); class Foo { private $eventDispatcher; function __construct($eventDispatcher) { var_dump($eventDispatcher); $this->eventDispatcher = $eventDispatcher; } function doStuff() { // ... call_user_func($this->eventDispatcher, "my_event", "my data"); } } ob_start(); $foo = new Foo(@e); e("my_event", 5, function($data) { echo "My event was called with '$data'";}); $foo->doStuff(); $output = ob_get_contents();ob_end_clean(); it( 'is perfectly possible to inject the event dispatcher as a dependency into classes.', $output === "My event was called with 'my data'" );
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: krsort(): Argument #1 ($array) must be of type array, null given in /in/eJhvp:1 Stack trace: #0 /in/eJhvp(1): krsort(NULL) #1 /in/eJhvp(6): e('event', 0, Object(Closure)) #2 {main} thrown in /in/eJhvp on line 1
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:
59.43 ms | 401 KiB | 8 Q