Advertisement
Guest User

better?

a guest
Sep 25th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <?php
  2. class Outer {
  3. protected $data;
  4.  
  5. public function __construct($data) {
  6. /* array access will be implemented by the time we get to here */
  7. $this->data = $data;
  8. }
  9.  
  10. public function getDataProxy() {
  11. /* create a proxy object implementing array access */
  12. return new class extends $this implements ArrayAccess {
  13. public function offsetGet($offset) { return $this->data[$offset]; }
  14. public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
  15. public function offsetUnset($offset) { unset($this->data[$offset]); }
  16. public function offsetExists($offset) { return isset($this->data[$offset]); }
  17. }($this->data);
  18. }
  19. }
  20.  
  21. $outer = new Outer($_SERVER);
  22. $proxy = $outer->getDataProxy();
  23.  
  24. var_dump($proxy["argv"]);
  25. var_dump($proxy["argc"]);
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement