Advertisement
NFL

Untitled

NFL
Jul 5th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. class A {
  4.  
  5.     protected $_a = [];
  6.     public function __call($name, $args) {
  7.         if (is_callable($this->$name)) {
  8.             return call_user_func($this->$name, $args);
  9.         } else {
  10.             throw new \RuntimeException("Method {$name} does not exist");
  11.         }
  12.     }
  13.  
  14.     public function __set($name, $value) {
  15.         $this->$name = is_callable($value) ?
  16.                 $value->bindTo($this, $this) :
  17.                 $value;
  18.     }
  19.     public function geta() {
  20.         return $this->_a;
  21.     }
  22.  
  23. }
  24. $a = new A;
  25. $a->foo = function() {
  26.     $this->_a[] = 'asasas';
  27.     $this->_a[] = 'asasas1';
  28.     $this->_a[] = 'asasas2';
  29. };
  30. $a->foo();
  31. var_dump($a->geta());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement