<?php
class PrivacyViolator
{
private $_caller;
function __construct() {
$this->_caller = function ($object, $method, $args) {
return call_user_func_array(array($object, $method), $args);
};
}
function callPrivateMethod($object, $method, $args) {
$this->_caller = Closure::bind($this->_caller, null, $object);
return $this->_caller->__invoke($object, $method, $args);
}
}
class MyClass
{
private function _hello($args) {
var_dump($args);
}
}
$myObject = new MyClass();
$privacyViolator = new PrivacyViolator();
$privacyViolator->callPrivateMethod($myObject, '_hello', array('world'));
preferences:
50.33 ms | 402 KiB | 5 Q