note 102706 rejected from functions.anonymous by danbrown
[email protected] Tue, 1 Mar 2011 09:34:30 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
Note Submitter: Parad0X dot UA at gmail dot com
----
Anyone knows of a better way to access $this from an anonymous function?
I'm currently using the following approach:
class Hello
{
public function world()
{
$array = array(1,2,3);
$that = $this;
return array_map(function($entry) use ($that) {
return $that->foo($entry);
});
}
public function foo($in)
{
return $out;
}
}
$hello = new Hello;
$hello->world();
Seems like a hack but works.