note 105887 deleted from functions.anonymous by tularis

From: Date: Fri, 23 Sep 2011 16:10:16 +0000
Subject: note 105887 deleted from functions.anonymous by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183388@lists.php.net to get a copy of this message
Note Submitter: neyronius at gmail dot com Reason: useless ---- Using $this within closure <?php class Test { public $a = 2; public $lambda = null; public function setLambda() { $_this = $this; //To prevent error $this->lambda = function() use ($_this) { echo $_this->a; //only public properties and methods }; } } $t = new Test; $t->setLambda(); $lambda = $t->lambda; // It's wrong to call lambda as $t->lambda(); $lambda(); //output: 2 ?>

« previous php.notes (#183388) next »