Last active
January 27, 2017 14:02
-
-
Save mustafaileri/f0d92e08629d72ce35d2643a1507a074 to your computer and use it in GitHub Desktop.
Call a private or protected method or property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function invokeRestrictedMethodAndProperties($object, $methodName, $args = [], $properties = []) | |
{ | |
$reflectionClass = new \ReflectionClass(get_class($object)); | |
$method = $reflectionClass->getMethod($methodName); | |
$method->setAccessible(true); | |
foreach ($properties as $propertyKey => $value) { | |
$prop = $reflectionClass->getProperty($propertyKey); | |
$prop->setAccessible(true); | |
$prop->setValue($object, $value); | |
} | |
return $method->invokeArgs($object, $args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment