Different methods call a validation method, I want to know which method called validation

Asked

Viewed 26 times

0

I have two methods that call the same method. In this method that was called (in this case, the validate()), I want to know what was the method that called it.

    public function increase()
    {
        $this->validate();
    }

    public function decrease()
    {
        $this->validate();
    }

    private function validate()
    {
        echo 'Quem me chamou? increase() ou decrease()?';
    }

1 answer

1


In php has the function debug_backtrace() that 'generates a backtrace', but generates in the current method

    $backtrace = debug_backtrace(); 

But we can turn the backtrace to a level to see where the call came from for that method

    array_shift($backtrace); 
    var_dump($backtrace); 
  • Absolutely! That’s exactly what I needed, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.