Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class A {
- protected $_a = [];
- public function __call($name, $args) {
- if (is_callable($this->$name)) {
- return call_user_func($this->$name, $args);
- } else {
- throw new \RuntimeException("Method {$name} does not exist");
- }
- }
- public function __set($name, $value) {
- $this->$name = is_callable($value) ?
- $value->bindTo($this, $this) :
- $value;
- }
- public function geta() {
- return $this->_a;
- }
- }
- $a = new A;
- $a->foo = function() {
- $this->_a[] = 'asasas';
- $this->_a[] = 'asasas1';
- $this->_a[] = 'asasas2';
- };
- $a->foo();
- var_dump($a->geta());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement