note 94805 added to functions.anonymous
| From: | rob at ubrio dot us | Date: | Wed, 25 Nov 2009 18:25:34 +0000 |
| Subject: | note 94805 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163285@lists.php.net to get a copy of this message | ||
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"
----
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/94805
Del: integrated -- https://master.php.net/note/delete/94805/integrated
Del: useless -- https://master.php.net/note/delete/94805/useless
Del: bad code -- https://master.php.net/note/delete/94805/bad+code
Del: spam -- https://master.php.net/note/delete/94805/spam
Del: non-english -- https://master.php.net/note/delete/94805/non-english
Del: in docs -- https://master.php.net/note/delete/94805/in+docs
Del: other reasons-- https://master.php.net/note/delete/94805
Reject -- https://master.php.net/note/reject/94805
Search -- https://master.php.net/manage/user-notes.php