3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Client { public function getUser(string $userId) { return [ 'id' => 5, ]; } } class Cache { public function set() { var_dump('Called set'); } public function get() { return null; } } class CachedClient { private $callee; private $cache; public function __construct($callee, $cache) { $this->callee = $callee; $this->cache = $cache; } public function __call(string $method, array $attributes) { $key = sprintf($method . '::' . implode(':', $attributes)); $result = $this->cache->get($key); if (!is_null($result)) { return $result; } $result = call_user_func_array([$this->client, $method], $attributes); $this->cache->set($key, $result); return $result; } } $client = new Client(); $cache = new Cache(); $cachedClient = new CachedClient($client, $cache); var_dump($cachedClient->getUser(5));
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined property: CachedClient::$client in /in/SQfl8 on line 48 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object in /in/SQfl8:48 Stack trace: #0 /in/SQfl8(60): CachedClient->__call('getUser', Array) #1 {main} thrown in /in/SQfl8 on line 48
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:
57.79 ms | 401 KiB | 8 Q