K
K
klsdycyn2019-10-07 11:23:22
WordPress
klsdycyn, 2019-10-07 11:23:22

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

3 answer(s)
A
Alexander Sobolev, 2018-06-27
@san_jorich

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

E
Eugene, 2019-10-07
@klsdycyn

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);

A
artsiom1976, 2019-10-07
@artsiom1976

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 question

Ask a Question

731 491 924 answers to any question