小编osc*_*ago的帖子

php:声明Function的参数类型

我正在尝试使用声明的参数类型创建一个函数,以快速检查它们是否采用正确的格式,但是当它返回一个字符串时我发生了以下错误:

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)

哪里出错了?

php arguments function

25
推荐指数
4
解决办法
5万
查看次数

Jquery .click()获得优势

在我的课程方法中,我有:

this.background.click(function() {
    this.terminate();
});
Run Code Online (Sandbox Code Playgroud)

显然this.terminate();不起作用因为this指的是this.background内部jquery.click功能.如何this从上级获得写作?

jquery click this

2
推荐指数
1
解决办法
206
查看次数

魔术方法__Call不适用于多个参数

我有魔术方法的问题 __call

以下代码运行良好,除非在方法调用中有多个参数.我尝试了不同的解决方案,没有任何好的结果(只是$argsimplode(', ' $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到无限的参数.

你知道如何修复多个参数的脚本吗?

php magic-methods

0
推荐指数
1
解决办法
1942
查看次数

标签 统计

php ×2

arguments ×1

click ×1

function ×1

jquery ×1

magic-methods ×1

this ×1