我正在尝试使用声明的参数类型创建一个函数,以快速检查它们是否采用正确的格式,但是当它返回一个字符串时我发生了以下错误:
Catchable fatal error: Argument 2 passed to myfunction() must be an instance of string, string given, called in path_to_file on line 69 and defined in path_to_file on line 49
例
function myfunction( array $ARRAY, string $STRING, int $INTEGER ) {
return "Args format correct";
}
myfunction(array("1",'2','3','4'), "test" , 1234);
Run Code Online (Sandbox Code Playgroud)
哪里出错了?
在我的课程方法中,我有:
this.background.click(function() {
this.terminate();
});
Run Code Online (Sandbox Code Playgroud)
显然this.terminate();不起作用因为this指的是this.background内部jquery.click功能.如何this从上级获得写作?
我有魔术方法的问题 __call
以下代码运行良好,除非在方法调用中有多个参数.我尝试了不同的解决方案,没有任何好的结果(只是$args或implode(', ' $args)不起作用)
public function __call($method, $args) {
if($this->methods[$method] != NULL)
return $this->objects[$this->methods[$method]]->$method($args[0]);
else trigger_error("Call undefined method " . $this->class . "::" . $method, E_USER_ERROR);
}
Run Code Online (Sandbox Code Playgroud)
如果我像这样写它也是有效的:
return $this->objects[$this->methods[$method]]->$method($args[0], $args[1], $args[3]);
Run Code Online (Sandbox Code Playgroud)
但正如您所看到的那样,这是不正确的,因为函数可以有0到无限的参数.
你知道如何修复多个参数的脚本吗?