<?php
class MyClass {
private function somePrivateMethod() {
echo 'This method is private!';
}
}
<?php
$MyObject = new MyClass();
$reflector = new ReflectionObject($MyObject);
$method = $reflector->getMethod('somePrivateMethod');
$method->setAccessible(true);
$method->invoke($MyObject); // This method is private!
Usind bind method:
$MyObject = new MyClass();
$closureBind = Closure::bind(function(MyClass $myClass) {
return $myClass->somePrivateMethod();
}, null, $MyObject);
$privateProperty = $closureBind($MyObject); // This method is private!
Using call method:
$MyObject = new MyClass();
(function () {
return $this->somePrivateMethod();
})->call($MyObject); // This method is private!