note 115412 deleted from reflectionmethod.invokeargs by salathe

From: Date: Mon, 21 Jul 2014 07:54:09 +0000
Subject: note 115412 deleted from reflectionmethod.invokeargs by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-199989@lists.php.net to get a copy of this message
Note Submitter: msajadi824 at hotmail dot com ---- A function to run a private or protected functions from a class: <?php function privateToPublic($class, $function, array $argumentForFunction = array()) { $method = new \ReflectionMethod($class, $function); $method->setAccessible(TRUE); return $method->invokeArgs($class,$argumentForFunction); } ?> example: <?php class a { private function test($a, $b) { return $a + $b; } } function privateToPublic($class, $function, array $argumentForFunction = array()) { $method = new \ReflectionMethod($class, $function); $method->setAccessible(TRUE); return $method->invokeArgs($class,$argumentForFunction); } echo privateToPublic(new a(), 'test', array(10,20)); ?> result: 30

« previous php.notes (#199989) next »