xref: /PHP-7.0/Zend/tests/dereference_005.phpt (revision 99c31b31)
1--TEST--
2Testing array dereference on object that implements ArrayAccess
3--FILE--
4<?php
5
6error_reporting(E_ALL);
7
8class obj implements arrayaccess {
9    private $container = array();
10    public function __construct() {
11        $this->container = array(
12            "one"   => 1,
13            "two"   => 2,
14            "three" => 3,
15        );
16    }
17    public function offsetSet($offset, $value) {
18        $this->container[$offset] = $value;
19    }
20    public function offsetExists($offset) {
21        return isset($this->container[$offset]);
22    }
23    public function offsetUnset($offset) {
24        unset($this->container[$offset]);
25    }
26    public function offsetGet($offset) {
27        return isset($this->container[$offset]) ? $this->container[$offset] : null;
28    }
29}
30
31function x() {
32	return new obj;
33}
34var_dump(x()['two']);
35
36?>
37--EXPECT--
38int(2)
39