Find out which class called a method in another class

后端 未结 8 2135
时光说笑
时光说笑 2020-11-27 06:10

Is there a way in PHP to find out what object called what method in another object.

Exmaple:

class Foo
{
  public function __construct()
  {
    $bar         


        
8条回答
  •  猫巷女王i
    2020-11-27 06:41

    At the very least, you could use debug_backtrace and analyze that to find the calling method.

    I think you should also be able to do it using the reflection API, but it's been too long since I've used PHP and I don't remember exactly how. The links should at least get you started, however.

提交回复
热议问题