note 94805 deleted from functions.anonymous by danbrown

From: Date: Wed, 25 Nov 2009 18:28:17 +0000
Subject: note 94805 deleted from functions.anonymous by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163287@lists.php.net to get a copy of this message
Note Submitter: rob at ubrio dot us ---- That last example should have been: <?php class Fun { protected function debug($message) { echo "DEBUG: $message\n"; } public function yield_something($callback) { return $callback("Soemthing!!"); } public function having_fun() { $self =& $this; return $this->yield_something(function($data) use (&$self) { $self->debug("Doing stuff to the data"); // do something with $data $self->debug("Finished doing stuff with the data."); }); } // Ah-Ha! public function __call($method, $args = array()) { if(is_callable(array($this, $method))) return call_user_func_array(array($this, $method), $args); } } $fun = new Fun(); echo $fun->having_fun(); ?> which is cleaner and avoids specifically using "__call"

« previous php.notes (#163287) next »