dragonsun2005 2015-03-20 04:07
浏览 33
已采纳

创建一个匿名对象并动态调用它的函数

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...

  • 写回答

1条回答 默认 最新

  • duandi2853 2015-03-20 04:44
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题