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 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口