note 102706 rejected from functions.anonymous by danbrown

From: Date: Tue, 01 Mar 2011 17:34:30 +0000
Subject: note 102706 rejected from functions.anonymous by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177454@lists.php.net to get a copy of this message
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.

« previous php.notes (#177454) next »