note 111140 added to reflectionmethod.getclosure

From: Date: Fri, 18 Jan 2013 20:05:10 +0000
Subject: note 111140 added to reflectionmethod.getclosure
Groups: php.notes 
Request: Send a blank email to php-notes+get-193208@lists.php.net to get a copy of this message
You can call private methods with getClosure(): <?php function call_private_method($object, $method, $args = array()) { $reflection = new ReflectionClass(get_class($object)); $closure = $reflection->getMethod($method)->getClosure($object); return call_user_func_array($closure, $args); } class Example { private $x = 1, $y = 10; private function sum() { print $this->x + $this->y; } } call_private_method(new Example(), 'sum'); ?> Output is 11. ---- Server IP: 69.147.83.199 Probable Submitter: 188.231.139.5 ---- Manual Page -- http://php.net/manual/en/reflectionmethod.getclosure.php Edit -- https://master.php.net/note/edit/111140 Del: integrated -- https://master.php.net/note/delete/111140/integrated Del: useless -- https://master.php.net/note/delete/111140/useless Del: bad code -- https://master.php.net/note/delete/111140/bad+code Del: spam -- https://master.php.net/note/delete/111140/spam Del: non-english -- https://master.php.net/note/delete/111140/non-english Del: in docs -- https://master.php.net/note/delete/111140/in+docs Del: other reasons-- https://master.php.net/note/delete/111140 Reject -- https://master.php.net/note/reject/111140 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193208) next »