Skip to content

Instantly share code, notes, and snippets.

@schmkr
Created October 2, 2013 19:21
Show Gist options
  • Save schmkr/6799124 to your computer and use it in GitHub Desktop.
Save schmkr/6799124 to your computer and use it in GitHub Desktop.
Get access to private methods (and properties), usefull for testing.
<?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