Я пытаюсь перегрузить мой метод в php, который работает довольно хорошо.Но когда я пытаюсь сделать то же самое в одном из моих проектов laravel, то я не могу увидеть вывод этой перегруженной функции.
class MyClass {
public function __call($name, $args) {
switch ($name) {
case 'funcOne':
switch (count($args)) {
case 1:
return call_user_func_array(array($this, 'funcOneWithOneArg'), $args);
case 3:
return call_user_func_array(array($this, 'funcOneWithThreeArgs'), $args);
}
case 'anotherFunc':
switch (count($args)) {
case 0:
return $this->anotherFuncWithNoArgs();
case 5:
return call_user_func_array(array($this, 'anotherFuncWithMoreArgs'), $args);
}
}
}
protected function funcOneWithOneArg($a) {
print($a);
}
protected function funcOneWithThreeArgs($a, $b, $c) {
print $a." ".$b." ".$c;
}
protected function anotherFuncWithNoArgs() {
print "Nothing";
}
protected function anotherFuncWithMoreArgs($a, $b, $c, $d, $e) {
print $a." ".$b." ".$c." ".$d." ".$e;
}
}
$s = new MyClass;
$s->anotherFunc(1, 2, 3, 4, 5);
, но когда я пытаюсь сделать то же самое, какследующее, я не получаю никакого вывода ::
В моем APIModel.php ::
public function __call($functionName, $arguments)
{
// TODO: Implement __call() method.
switch ($functionName){
case 'executeRestAPI':
switch (count($arguments)){
case 3:
dd("aa");
return call_user_func(array($this, 'executeRestAPIWithThree'), $arguments);
case 4:
return call_user_func(array($this, 'executeRestAPIWithFour'), $arguments);
}
}
}
protected function executeRestAPIWithThree($methodType, $request = array(), $referenceID = null){
dd(12);
if (isset($referenceID))
$this->apiEntity = $this->apiEntity."/".$referenceID;
$response = $this->httpClient->request($methodType,$this->apiEntity, ['query' => $request]);
dd($response);
return $response;
}
Теперь я вызываю этот метод из другого класса ::
public function results(Request $request){
$params = $request->all();
unset($params['_token']);
$absModel = new AbstractAPIModel('ssbsect');
$absModel->executeRestAPI("GET", $params);
Здесь я не получаю никакого вывода.Даже я пытался напечатать «12», чтобы проверить, вызывает ли эта функция или нет.Но я не нашел никакого успеха.