Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TEST--
- test __toString character access vs ArrayAccess
- --FILE--
- <?php
- class Test implements ArrayAccess {
- private $items = [];
- public function offsetExists($offset) {
- return array_key_exists($offset, $this->items);
- }
- public function offsetSet($offset, $value) {
- if ($offset === NULL) {
- $this->items[] = $value;
- } else {
- $this->items[$offset] = $value;
- }
- }
- public function offsetUnset($offset) {
- unset($this->items[$offset]);
- }
- public function offsetGet($offset) {
- return $this->offsetExists($offset) ? $this->items[$offset] : NULL;
- }
- public function __toString() {
- return 'TEST';
- }
- }
- $test = new Test;
- $test[] = 'One';
- $test[] = 'Two';
- $test[] = 'Three';
- var_dump($test[2]);
- var_dump($test{2});
- ?>
- --EXPECT--
- string(5) "Three"
- string(1) "S"
Advertisement
Add Comment
Please, Sign In to add comment