summaryrefslogtreecommitdiff
path: root/Zend/tests/anon/004.phpt
blob: 8751bceb8c1e5249fb59f752c7a1699c04753139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--TEST--
testing anonymous inheritance
--FILE--
<?php
class Outer {
    protected $data;

    public function __construct($data) {
        $this->data = $data;
    }

    public function getArrayAccess() {
        /* create a proxy object implementing array access */
        return new class($this->data) extends Outer implements ArrayAccess {
            public function offsetGet($offset)          { return $this->data[$offset]; }
            public function offsetSet($offset, $data)   { return ($this->data[$offset] = $data); }
            public function offsetUnset($offset)        { unset($this->data[$offset]); }
            public function offsetExists($offset)       { return isset($this->data[$offset]); }
        };
    }
}

$outer = new Outer(array(
    rand(1, 100)
));

/* not null because inheritance */
var_dump($outer->getArrayAccess()[0]);
?>
--EXPECTF--
int(%d)