Get child class namespace from superclass in PHP

后端 未结 6 1042
南旧
南旧 2020-12-09 02:24

Assuming I have the following classes in different files:



        
6条回答
  •  离开以前
    2020-12-09 02:49

    You can also do this in your getNamespace() method:

    return get_class($this);
    

    When called from childclass, the result will be:

    MyNS\SubNS\childclass
    

    If you don't want the class name on the end, just chop off everything from the last \ to the end.

提交回复
热议问题