<?php
class PrivateClass
{
private function privateMethod()
{
return 'никогда так не делайте';
}
}
$object = new PrivateClass();
$reflector = new ReflectionObject($object);
$method = $reflector->getMethod('privateMethod');
$method->setAccessible(true);
echo $method->invoke($object);
class Test {
private static function run() {
echo __METHOD__;
}
}
$method = new ReflectionMethod('Test', 'run');
$method->setAccessible(true);
$method->invoke(new Test);