创建一个匿名对象并动态调用它的函数
问题描述:
I'm trying to create some kind of dispatcher for my web (cuz i have to do it manually and idk how can i do this)
$uri = array_filter(explode("/", filter_input(INPUT_SERVER, "PATH_INFO")));
$_SERVER["URI"] = $uri;
switch (sizeof($uri)) {
case 0:
error();
exit(0);
break;
case 1:
call_user_func("$uri[1]::__construct");
break;
default :
call_user_method_array("$uri[2]", call_user_func("$uri[1]::getInstance"));
break;
}
That's what i have but i get this:
- Strict standards: Only variables should be passed by reference in C:\wamp\www\BACK\index.php on line 180
- Deprecated: Function call_user_method_array() is deprecated in C:\wamp\www\BACK\index.php on line 180
- Warning: call_user_method_array() expects exactly 3 parameters, 2 given in C:\wamp\www\BACK\index.php on line 180
Sending http://localhost/BACK/index.php/Page/data?asd=1
and
- Warning: call_user_func() expects parameter 1 to be a valid callback, non-static method Page::__construct() cannot be called statically in C:\wamp\www\BACK\index.php on line 17
Sending http://localhost/BACK/index.php/Page?asd=1
I know i'm totally wrong but i can't find help...
我正在尝试为我的网站创建某种调度程序(因为我必须手动执行此操作并且如何 我可以这样做吗) p>
$ uri = array_filter(explode(“/”,filter_input(INPUT_SERVER,“PATH_INFO”)));
$ _SERVER [“URI”] = $ uri;
switch(sizeof($ uri)){
case 0:
error();
exit(0);
break;
case 1:
call_user_func(“$ uri [1] :: __ construct“);
break;
默认值:
call_user_method_array(”$ uri [2]“,call_user_func(”$ uri [1] :: getInstance“));
break;
}
code> pre>
这就是我所拥有的,但我得到了这个: p>
- 严格的标准:只有变量应该是 在第180行的C:\ wamp \ www \ BACK \ index.php中通过引用传递 li>
- 不推荐使用:函数call_user_method_array()在C:\ wamp \ www \ BACK \ index.php中不推荐使用 第180行 li>
- 警告:call_user_method_array()需要3个参数,2在C:\ wamp \ www \ BACK \ index.php第180行中给出 li>
ul> \ ñ
发送 http://localhost/BACK/index.php/Page/data? asd = 1 p>
和 p>
- 警告:call_user_func()期望参数1是有效的回调,非 -static方法Page :: __ construct()不能在第17行的C:\ wamp \ www \ BACK \ index.php中静态调用 li>
ul>
发送 http://localhost/BACK/index.php/Page?asd = 1 p >
我知道我完全错了,但我找不到帮助...... p>
div>
答
I change my function and is working correctly now
$uri = array_filter(explode("/", filter_input(INPUT_SERVER, "PATH_INFO")));
$_SERVER["URI"] = $uri;
switch (sizeof($uri)) {
case 0:
error();
exit(0);
break;
case 1:
$refClass = new ReflectionClass("$uri[1]");
$class_instance = $refClass->newInstanceArgs((array) null);
break;
default :
$refClass = new ReflectionClass("$uri[1]");
$class_instance = $refClass->newInstanceArgs((array) null);
$class_instance->$uri[2]();
break;
}