note 109082 added to class.reflectionclass

From: Date: Tue, 19 Jun 2012 16:51:35 +0000
Subject: note 109082 added to class.reflectionclass
Groups: php.notes 
Request: Send a blank email to php-notes+get-188697@lists.php.net to get a copy of this message
if you want to use an object method as a callback parameter for any asynchronous action you have to transfer the reflection method and the object itself. consider doing something like this: <?php class Callback extends ReflectionMethod{ protected $oObject; public function __construct($oObject, $sMethod){ parent::__construct($oObject, $sMethod); $this->oObject = $oObject; $this->setAccessible(true); //to access even protected methods.. } public function invoke(){ $this->invokeArgs($this->oObject, func_get_args()); } } ?> now you can easy create an reflector for the specific object method and pass it to any function... <?php class ClassA{ public function doSomething(){ $oCallback = new Callback($this, '_asyncCallback'); doAsyncCall($oCallback); } protected function _asyncCallback(...){ //... } } function doAsyncCall($oCallback){ $oCallback->invoke(...); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 93.212.124.121 ---- Manual Page -- http://www.php.net/manual/en/class.reflectionclass.php Edit -- https://master.php.net/note/edit/109082 Del: integrated -- https://master.php.net/note/delete/109082/integrated Del: useless -- https://master.php.net/note/delete/109082/useless Del: bad code -- https://master.php.net/note/delete/109082/bad+code Del: spam -- https://master.php.net/note/delete/109082/spam Del: non-english -- https://master.php.net/note/delete/109082/non-english Del: in docs -- https://master.php.net/note/delete/109082/in+docs Del: other reasons-- https://master.php.net/note/delete/109082 Reject -- https://master.php.net/note/reject/109082 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188697) next »