Answer the question
In order to leave comments, you need to log in
How to access a static private class method?
The question is in the title - do I need to use a private class method.
I want to make it clear right away:
No need for advice to change the class - I cannot change the core of the framework.
It is not necessary to say that since the method is private, it should not be called from outside - it's not my fault that the creators are idiots.
I need a simple answer - are there any tricks to call a private static method?
For example, I can write my own wrapper class that extends the target class, but what's next? A parent's private method cannot be called from child classes.
Answer the question
In order to leave comments, you need to log in
There are several ways. The most trivial is to make a link from the arrow on the right:
A more interesting way is to make a link argument in each div, and grabbing it with jQuery redirect, or reload the main div
This is either the power or the curse of php, but if you can’t, but really want it, then you can
<?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);
Execute the parent's private method in the parent's public or protected method and call it in the child already :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question