note 93417 added to functions.anonymous

From: Date: Wed, 09 Sep 2009 10:38:39 +0000
Subject: note 93417 added to functions.anonymous
Groups: php.notes 
Request: Send a blank email to php-notes+get-160342@lists.php.net to get a copy of this message
/** * Using closures to dynamically extend objects * */ class ClosureTest{ public $member = 'test'; protected $protectedMember = 'protectedtest'; public function __call($method, $args) { return call_user_func_array( $this->$method, $args); } } $object = new ClosureTest(); $object->closure = function() use ($object){ return $object->member; }; echo $object->closure(); /** * This won't work, you can not access protected/private members, which is fine. $object->closureAccessProtected = function() use ($object){ return $object->protectedMember; }; $object->closureAccessProtected(); */ ---- Server IP: 80.81.171.181 Probable Submitter: 130.233.143.14 ---- Manual Page -- http://www.php.net/manual/en/functions.anonymous.php Edit -- https://master.php.net/note/edit/93417 Del: integrated -- https://master.php.net/note/delete/93417/integrated Del: useless -- https://master.php.net/note/delete/93417/useless Del: bad code -- https://master.php.net/note/delete/93417/bad+code Del: spam -- https://master.php.net/note/delete/93417/spam Del: non-english -- https://master.php.net/note/delete/93417/non-english Del: in docs -- https://master.php.net/note/delete/93417/in+docs Del: other reasons-- https://master.php.net/note/delete/93417 Reject -- https://master.php.net/note/reject/93417 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160342) next »