Dynamic binding in static method php
-
30-06-2021 - |
Frage
class A
{
static function get_name_derived_class()
{
//This function must return the name of the real class
//Is it possible without insert a methon in B class?
{
}
class B extends A
{
}
B::test()
I'd like to have a static methon in base class which returns the name of real (derived) class, without insert a specific method in it. is it possible? thanx
Lösung
<?php
class A
{
static function test()
{
return get_called_class();
}
}
class B extends A
{
}
echo B::test();
Requires PHP >= 5.3.0. See PHP's manual entry on Late Static Bindings
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow