tags:

views:

28

answers:

2

Here is a sample class:


class A{
    .
    .
    .
    public function updateAction(){
        $tags=explode(' ',$taglist);
        .
        .
        .
        $tagsInDb=$tagsInDb->toArray();
        $dif=array_diff_uassoc($tags,$tagsInDb,"here the callback should be inserted");
    }
    protected function callback_function_for_array_diff($a,$b){
    }
}

How can I call callback_function_for_array_diff as a callback function for array_diff_uassoc?

A: 

use

array("class_name","func name")

like

 $dif=array_diff_uassoc($tags,$tagsInDb,array($this,"callback_function_for_array_diff"));
Haim Evgi
Actually, it would be `array($this, 'func name')` because he isn't calling a static method.
Daniel Egeberg
you right i in my way to rewrite my answer and say that usually i defined this function as static function
Haim Evgi
+1  A: 

The different types of specifying a callback are described here:

http://www.php.net/manual/en/function.call-user-func.php

As you do not have a static function, you need an instance of the class, i.e. $this

So you can specify the callback as array($this, callback_function_for_array_diff)

Or you make a

static function callback_function_for_array_diff($a,$b){

Then it would be "A::callback_function_for_array_diff" or array("A","callback_function_for_array_diff")

Alex