3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Resolvable implements ArrayAccess, IteratorAggregate, Countable { protected $callable; protected $resolved = null; public function __construct( callable $closure ) { $this->callable = $closure; } public function __invoke( ...$args ) { if ( ! $this->resolved ) { $this->resolved = call_user_func_array( $this->callable, $args ); // Any normalisation can be done here. } return $this->resolved; } public function offsetExists( mixed $k ) : bool { $this->__invoke(); return isset( $this->resolved[ $k ] ); } public function &offsetGet( mixed $k ) : mixed { $this->__invoke(); return $this->resolved[ $k ]; } public function offsetSet( mixed $k, mixed $v ) : void { $this->__invoke(); $this->resolved[ $k ] = $v; } public function offsetUnset( mixed $k ) : void { $this->__invoke(); unset( $this->resolved[ $k ] ); } public function getIterator(): Traversable { $this->__invoke(); return new ArrayIterator( $this->resolved ); } public function count() : int { $this->__invoke(); return count( $this->resolved ); } } // $foo = function () { return 1; }; $endpoints = [ '/wp/v2/users' => fn () => [ [ 'method' => 'GET', 'callback' => fn () => true, 'args' => [ 'id' => [], ], ], [ 'method' => 'POST', 'callback' => fn () => true, 'args' => [ 'id' => [], ], ], ], ]; foreach ( $endpoints as $k => &$ep ) { if ( is_callable( $ep ) ) { $ep = new Resolvable( $ep ); } } // Old-style plugin, eg Really Simple SSL: if ( isset( $endpoints['/wp/v2/users'] ) ) { // Save the original endpoint $original_endpoint = $endpoints['/wp/v2/users']; // Override the GET callback $endpoints['/wp/v2/users'][0]['callback'] = function() { return 'Sorry, you are not allowed to access users without authentication.'; }; // Preserve the original args and permission callback $endpoints['/wp/v2/users'][0]['args'] = $original_endpoint[0]['args']; $endpoints['/wp/v2/users'][0]['permission_callback'] = '__return_true'; } var_dump( $endpoints ); var_dump( $endpoints['/wp/v2/users'][0]['callback']() );

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.180.0210.01019.68
8.4.90.0060.00317.89
8.3.180.0020.00616.78
8.3.50.0030.00516.74

preferences:
55.45 ms | 506 KiB | 5 Q