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 8.0.10 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.
Output for 8.0.0 - 8.0.9
Warning: Undefined property: CachedClient::$client in /in/SQfl8 on line 48 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) 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.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
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 7.3.32 - 7.3.33
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

preferences:
158.36 ms | 402 KiB | 191 Q