xref: /PHP-7.1/Zend/tests/anon/004.phpt (revision 49608e06)
1--TEST--
2testing anonymous inheritance
3--FILE--
4<?php
5class Outer {
6    protected $data;
7
8    public function __construct($data) {
9        $this->data = $data;
10    }
11
12    public function getArrayAccess() {
13        /* create a proxy object implementing array access */
14        return new class($this->data) extends Outer implements ArrayAccess {
15            public function offsetGet($offset)          { return $this->data[$offset]; }
16            public function offsetSet($offset, $data)   { return ($this->data[$offset] = $data); }
17            public function offsetUnset($offset)        { unset($this->data[$offset]); }
18            public function offsetExists($offset)       { return isset($this->data[$offset]); }
19        };
20    }
21}
22
23$outer = new Outer(array(
24    rand(1, 100)
25));
26
27/* not null because inheritance */
28var_dump($outer->getArrayAccess()[0]);
29--EXPECTF--
30int(%d)
31