Difference between ::class and get_class

后端 未结 3 2038
死守一世寂寞
死守一世寂寞 2021-01-11 19:38

Can you explain the difference between get_class($instance) and ClassName::class ?



        
3条回答
  •  日久生厌
    2021-01-11 20:30

    Classnames aren't case sentive in PHP.

    It seems like get_class($obj) returns true classname (in PHP core) and ::class returns the classname used in user's code.

    // From PHP Team : The '::class' construct is done purely at compile time, based of the apparent classname passed in. It does not check the spelling of the actual class name, or even that the class exist

提交回复
热议问题