note 102706 added to functions.anonymous

From: Date: Tue, 01 Mar 2011 17:33:51 +0000
Subject: note 102706 added to functions.anonymous
Groups: php.notes 
Request: Send a blank email to php-notes+get-177453@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 69.193.179.210 ---- Manual Page -- http://www.php.net/manual/en/functions.anonymous.php Edit -- https://master.php.net/note/edit/102706 Del: integrated -- https://master.php.net/note/delete/102706/integrated Del: useless -- https://master.php.net/note/delete/102706/useless Del: bad code -- https://master.php.net/note/delete/102706/bad+code Del: spam -- https://master.php.net/note/delete/102706/spam Del: non-english -- https://master.php.net/note/delete/102706/non-english Del: in docs -- https://master.php.net/note/delete/102706/in+docs Del: other reasons-- https://master.php.net/note/delete/102706 Reject -- https://master.php.net/note/reject/102706 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177453) next »