Download src/php/php-src/Zend/tests/anon/005.phpt from meddyrat/dis-bench: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/Zend/tests/anon/005.phpt
- Command line
-
hf download hf://datasets/meddyrat/dis-bench/src/php/php-src/Zend/tests/anon/005.phpt
-
curl -L -o 005.phpt https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/Zend/tests/anon/005.phpt
1.13 kB
| --TEST-- | |
| testing reusing anons that implement an interface | |
| --FILE-- | |
| class Outer { | |
| protected $data; | |
| public function __construct(&$data) { | |
| /* array access will be implemented by the time we get to here */ | |
| $this->data = &$data; | |
| } | |
| public function getArrayAccess() { | |
| /* create a child object implementing array access */ | |
| /* this grants you access to protected methods and members */ | |
| return new class($this->data) implements ArrayAccess { | |
| public function offsetGet($offset): mixed { return $this->data[$offset]; } | |
| public function offsetSet($offset, $data): void { $this->data[$offset] = $data; } | |
| public function offsetUnset($offset): void { unset($this->data[$offset]); } | |
| public function offsetExists($offset): bool { return isset($this->data[$offset]); } | |
| }; | |
| } | |
| } | |
| $data = array( | |
| rand(1, 100), | |
| rand(2, 200) | |
| ); | |
| $outer = new Outer($data); | |
| $proxy = $outer->getArrayAccess(); | |
| /* null because no inheritance, so no access to protected member */ | |
| var_dump(@$outer->getArrayAccess()[0]); | |
| --EXPECT-- | |
| NULL | |