Alex
Alex

Reputation: 68406

How to find if a callback is a specific method?

At one point I have:

$callback = array(&$this, 'foo');

How can I find out later if $callback is the foo method?

if($callback == array(&$this, 'foo')) doesn't seem to work

Upvotes: 1

Views: 64

Answers (2)

jianfeng
jianfeng

Reputation: 2590

<?php
class A
{
    public function Test1()
    {
        $callback = array(&$this, 'foo');
        var_dump($callback == array(&$this, 'foo'));
    }

    public function foo()
    {
    }   
}

$a = new A();
$a->Test1();
?>

Upvotes: 1

user229044
user229044

Reputation: 239250

Callbacks are just simple arrays, and the method name is a string. Just check the second element of the array:

if ($callback[1] == 'foo')

Upvotes: 2

Related Questions