Download src/php/php-src/Zend/tests/ArrayAccess/bug71731.phpt from meddyrat/dis-bench: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/Zend/tests/ArrayAccess/bug71731.phpt
- Command line
-
hf download hf://datasets/meddyrat/dis-bench/src/php/php-src/Zend/tests/ArrayAccess/bug71731.phpt
-
curl -L -o bug71731.phpt https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/Zend/tests/ArrayAccess/bug71731.phpt
1.33 kB
| --TEST-- | |
| Bug #71731: Null coalescing operator and ArrayAccess | |
| --FILE-- | |
| class AA implements ArrayAccess { | |
| private $data = []; | |
| public function offsetExists($name): bool { | |
| echo "offsetExists($name)\n"; | |
| return array_key_exists($name, $this->data); | |
| } | |
| public function &offsetGet($name): mixed { | |
| echo "offsetGet($name)\n"; | |
| if (!array_key_exists($name, $this->data)) { | |
| throw new Exception('Unknown offset'); | |
| } | |
| return $this->data[$name]; | |
| } | |
| public function offsetSet($name, $value): void { | |
| echo "offsetSet($name)\n"; | |
| $this->data[$name] = $value; | |
| } | |
| public function offsetUnset($name): void { | |
| echo "offsetUnset($name)\n"; | |
| unset($this->data[$name]); | |
| } | |
| } | |
| $aa = new AA; | |
| var_dump(isset($aa[0][1][2])); | |
| var_dump(isset($aa[0]->foo)); | |
| var_dump($aa[0] ?? 42); | |
| var_dump($aa[0][1][2] ?? 42); | |
| $aa[0] = new AA; | |
| $aa[0][1] = new AA; | |
| var_dump(isset($aa[0][1][2])); | |
| var_dump($aa[0][1][2] ?? 42); | |
| --EXPECT-- | |
| offsetExists(0) | |
| bool(false) | |
| offsetExists(0) | |
| bool(false) | |
| offsetExists(0) | |
| int(42) | |
| offsetExists(0) | |
| int(42) | |
| offsetSet(0) | |
| offsetGet(0) | |
| offsetSet(1) | |
| offsetExists(0) | |
| offsetGet(0) | |
| offsetExists(1) | |
| offsetGet(1) | |
| offsetExists(2) | |
| bool(false) | |
| offsetExists(0) | |
| offsetGet(0) | |
| offsetExists(1) | |
| offsetGet(1) | |
| offsetExists(2) | |
| int(42) | |