Use of Callback without anonymous function in php?

0

I'm looking for how to do a callback function that does not pass as an anonymous function callback but an already declared function.

I understand that to call a callback I can do it this way

private function create($callback)
    {
     //acciones
      if(is_callable($callback)){
        call_user_func($callback,$billModel);
      }
    }

call of the unfcion

this->create(function($model){
 echo $model;
})

but in the previous example an anonymous function is used what I want is to pass it not an anonymous function but a function already declared for example

    private function create($callback)
    {
      //acciones
      if(is_callable($callback)){
        call_user_func($callback,$billModel);
      }
    }


    private function attachInstances($billModel)
    {
      //hace algo
    }

//llamado de la function 
$this->create($this->attachInstances)

Try to make that call of the works but it does not work

    
asked by FuriosoJack 19.10.2017 в 16:47
source

1 answer

1

Pass the name of the function as parameter a.

call_user_func('my_callback_function');

call_user_func(array('MyClass', 'myCallbackMethod'));

is_callable(array('Foo', '__construct'))

test:

$this->create(array($this,'attachInstances'))
    
answered by 19.10.2017 / 23:16
source