Answer the question
In order to leave comments, you need to log in
How to get class name from static method?
There is code similar to this:
class A extends B {}
abstract class B {
static function show(){
//здесь хочу получить имя класса, от которого был вызван метод
}
}
class D{
public function init() {
A::show();
}
}
$object = new D();
D->init();
Answer the question
In order to leave comments, you need to log in
I still don’t understand that you want to get
AB or D at the output
here for A
class A extends B {}
abstract class B {
public static function show(){
echo static::class;
//здесь хочу получить имя класса, от которого был вызван метод
}
}
class D{
public function init() {
A::show();
}
}
$object = new D();
$object->init();
class A extends B {}
abstract class B {
public static function show(){
echo self::class;
//здесь хочу получить имя класса, от которого был вызван метод
}
}
class D{
public function init() {
A::show();
}
}
$object = new D();
$object->init();
get_called_class(): php.net/manual/function.get-called-class.php
What you want is called "late static binding".
Introduced in PHP 5.4
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question