3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements ArrayAccess{ private $r; function __construct() { $this->r = range("A","Z"); } public function offsetSet($offset, $value) { $this->r[$offset] = $value; } public function offsetExists($offset) { return isset($this->r[$offset]); } public function offsetUnset($offset) { unset($this->r[$offset]); } public function offsetGet($offset) { return isset($this->r[$offset]) ? $this->r[$offset] : null; } function __invoke($var) { return range("A", "Z")[$var]; } function a() { return range("A", "Z"); } function b($v) { return range("A", "Z")[$v]; } } $t = new Test(); echo $t(0); // Works echo (new Test())[0]; // works echo (new Test())->a()[0]; // works echo (new Test())->b(0); // works //echo (new Test())(0); // error ?>

preferences:
34.14 ms | 402 KiB | 5 Q