- var_dump: documentation ( source)
<?php
class PrivacyViolator
{
private $caller;
function __construct()
{
$this->caller = function ($method, $args) {
return call_user_func_array([$this, $method], $args);
};
}
function callPrivateMethod($object, $method, $args)
{
var_dump($method);
$this->caller->bindTo($object, $object);
return $this->caller($method, $args);
}
}
class MyClass {
private $private_var;
private function hello() {
return "I'm private method";
}
}
$myObject = new MyClass();
$privacyViolator = new PrivacyViolator();
$privacyViolator->callPrivateMethod($myObject, 'hello', ['world']);