forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path005.phpt
37 lines (32 loc) · 1.08 KB
/
005.phpt
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
32
33
34
35
36
37
--TEST--
testing reusing anons that implement an interface
--FILE--
<?php
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) { 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]); }
};
}
}
$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