note 102074 deleted from language.oop5.overloading by danbrown

From: Date: Wed, 26 Jan 2011 14:09:01 +0000
Subject: note 102074 deleted from language.oop5.overloading by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176332@lists.php.net to get a copy of this message
Note Submitter: relingija at gmail dot com ---- Previous example can be easily modificated to access $this: <?php class Object { // generic class allowing dynamic addition of methods public $methods = array(); // list of all custom added methods function __call($fnc, $args) { array_unshift($args, $this); return call_user_func_array($this->methods[$fnc], $args); } } // Example adding a new custom method $test = new Object; $test->b = "sample text"; $test->methods['do_something'] = function ($self, $var1, $var2) { echo "custom method called with $var1, $var2 and using $self->b\n"; }; $test->do_something('asdf', 'test1'); ?> Naw you can use anon function with reference to $this.

« previous php.notes (#176332) next »