문제

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

도움이 되었습니까?

해결책

<?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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top