Как вызвать call_user_func_array для объекта, который был установлен в переменную?

Если бы я назначил объект переменной экземпляра модели, как бы я использовал для него call_user_func_array?

use App\Repositories\BaseRepositoryDynamic as BR;
$repo = new BR();
$repo->model=new User();
$repo->first();





class BaseRepositoryDynamic
{
public $model;

public function __call($name, $parameters=[])
{
call_user_func_array($this->model->$name, $parameters);
}
}

Я получаю эту ошибку:

call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /Users/admin/Projects/app/Repositories/BaseRepositoryDynamic.php on line 16

0

Решение

В документах:

// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four"));

Пример:

class Model
{
public $model;

public function __call($name, $params = [])
{
call_user_func_array([$this->model, $name], $params);
}
}

class User
{
public function first($one, $two)
{
echo $one, $two;
}
}

$example = new Example();

$example->model = new User();

$example->first('one', 'two');
1

Другие решения

Других решений пока нет …