Functionality of PHP get_class

前端 未结 1 1043
小鲜肉
小鲜肉 2021-01-28 02:57

Can anyone explain why is the get_class function returning different values below? Specifically, what is it supposed to do when it is called in a base class and whe

相关标签:
1条回答
  • 2021-01-28 03:19

    It seems quite well explained in the documentation, but here it is:

    get_class($instance) returns the class of the $instance instance, regardless of where you're calling it; get_class($this) does behave the same way, returning the class of $this.

    get_class() returns the class where the method calling it is defined, thus it returns bar in your example, as that is where __construct() is defined (even though you're calling it through inheritance).

    0 讨论(0)
提交回复
热议问题