vendredi 29 mai 2015

php: Is it possible to access a private static method, possibly by reflection?

Is it possible to access a private static method, possibly by reflection?

The following code successfully accesses a private non-static method:

$method = new ReflectionMethod('MyClass', 'myPrivateMethod');
$method->setAccessible(true);
echo $method->invoke(new MyClass);

However, attempting to access a private static method in the same manner results in:

ReflectionException: Method MyClass::myPrivateStaticMethod() does not exist





Aucun commentaire:

Enregistrer un commentaire