note 94804 added to functions.anonymous

From: Date: Wed, 25 Nov 2009 18:20:03 +0000
Subject: note 94804 added to functions.anonymous
Groups: php.notes 
Request: Send a blank email to php-notes+get-163284@lists.php.net to get a copy of this message
You can always call protected members using the __call() method - similar to how you hack around this in Ruby using send. <?php class Fun { protected function debug($message) { echo "DEBUG: $message"; } public function yield_something($callback) { return $callback("Soemthing!!"); } public function having_fun() { $self =& $this; return $this->yield_something(function($data) use (&$self) { $self->__call('debug', "Doing stuff to the data"); // do something with $data $self->__call('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($this, $method), $args); } } $fun = new Fun(); echo $fun->having_fun(); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 198.185.18.207 ---- Manual Page -- http://www.php.net/manual/en/functions.anonymous.php Edit -- https://master.php.net/note/edit/94804 Del: integrated -- https://master.php.net/note/delete/94804/integrated Del: useless -- https://master.php.net/note/delete/94804/useless Del: bad code -- https://master.php.net/note/delete/94804/bad+code Del: spam -- https://master.php.net/note/delete/94804/spam Del: non-english -- https://master.php.net/note/delete/94804/non-english Del: in docs -- https://master.php.net/note/delete/94804/in+docs Del: other reasons-- https://master.php.net/note/delete/94804 Reject -- https://master.php.net/note/reject/94804 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163284) next »