Created
October 2, 2013 19:21
-
-
Save schmkr/6799124 to your computer and use it in GitHub Desktop.
Get access to private methods (and properties), usefull for testing.
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 | |
trait PrivateMethodCallerTrait { | |
protected function callPrivateMethod($object, $methodName, $args = array()) { | |
$fn = function($methodName, $args) { | |
return call_user_func_array(array($this, $methodName), $args); | |
}; | |
$privateAccessor = $fn->bindTo($object,$object); | |
return $privateAccessor($methodName,$args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment