3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 7.1.0 - 7.3.0beta1
Notice: Undefined property: CachedClient::$client in /in/SQfl8 on line 48 Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/SQfl8 on line 48 string(10) "Called set" NULL
Output for hhvm-3.22.0
Notice: Undefined property: CachedClient::$client in /in/SQfl8 on line -1 Warning: Invalid argument: function: not a valid callback array in /in/SQfl8 on line -1 string(10) "Called set" NULL
Output for hhvm-3.18.5 - 3.21.3
Notice: Undefined property: CachedClient::$client in /in/SQfl8 on line 48 Warning: Invalid argument: function: not a valid callback array in /in/SQfl8 on line 48 string(10) "Called set" NULL
Output for 5.6.0 - 5.6.30
Catchable fatal error: Argument 1 passed to CachedClient::__call() must be an instance of string, string given in /in/SQfl8 on line 38
Process exited with code 255.