note 93417 deleted from functions.anonymous by thiago
| From: | thiago@php.net | Date: | Wed, 09 Sep 2009 13:11:19 +0000 |
| Subject: | note 93417 deleted from functions.anonymous by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160346@lists.php.net to get a copy of this message | ||
Note Submitter: Jaakko Salmela
----
/**
* 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();
*/