douxigai8757 2011-01-21 09:27
浏览 69
已采纳

从路由器获取计数控制器args?

ok im learning on how to make my own custom mvc system, so far i have created things like router and the controller.

example i have a controller profile class and an url www.helloworld.com/args1/args2/args3

class Profiles
{
    function index($args1,$args2)
    {
        echo var_dump($args1,$args2);
    }
}

heres are part of my router class that execute the method and the parms

        if (is_callable(array($controller,$method))) {
            call_user_func_array(array($controller, $method), $this->params);
        }

so far no error but somehow i need to give a 404. if the $this->params is different then the count(params) in the method that i call at call_user_func_array(array($controller, $method), $this->params);

ok what im thinking is if count get params not same as count params at the called class then 404, lets say i can count my $this->params it gave me a 3. but how about the params in the called class ? how can we count params in a called class by call_user_func_array?

Thanks for looking in

Adam Ramadhan

  • 写回答

3条回答 默认 最新

  • doucandiao9180 2011-01-21 09:35
    关注

    From what I know, there is no way of getting the parameter count for a method without using reflection. However, it's pretty simple and would look something like this:

    $reflector = new ReflectionClass('Profiles');
    $method = $reflector->getMethod('index');
    $parameters = $method->getParameters();
    
    printf('%s expects %d parameters', $method->name, count($parameters));
    

    Will yield

    index expects 2 parameter
    

    Note that reflection always comes with a cost. However, the performance implications of this should not be noticable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi
  • ¥15 ue2.6.12版本用的若以,安装gojs,引入import * as go from 'gojs';报错
  • ¥15 服务器上的网站安装php5.6版本
  • ¥15 请大咖一起探索iptv 直播源的hls通过反向代理解密
  • ¥100 寻找技术员 云闪付tn转h5输入卡号付款的链接 重酬!