N
N
Nicholas2014-02-01 18:44:20
PHP
Nicholas, 2014-02-01 18:44:20

How to get caller class name PHP

How to get the name of the class that called the action in the parent class?
Example:

class ParentClass {
    function action() {
        echo $className;
    }
}

class ChildClass extends ParentClass {}

$parentClass = new ParentClass();
$parentClass->action();     // ParentClass

$childClass = new ChildClass();
$childClass->action();      // ChildClass

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikolai, 2014-02-01
Sumrak @NikolasSumrak

I'm sorry, get_called_class()

D
Danny Chernyavsky, 2014-02-01
@DEHisOK

class ParentClass {
    function action() {
        echo get_class($this);
    }
}

V
Vladimir Golub, 2015-03-18
@RazerVG

That is, roughly speaking. The problem is that the start can take a value either from the cross table or from the clutch table?
The description of the question is not too clear, I would make a schematic in workbeanch or something like that. There would be more answers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question