doudiyu1639 2015-03-07 16:21
浏览 95
已采纳

call_user_func_array不接受意外的函数参数

I have a function which accepts no parameters, i.e. function doSomething(){...}.

If I run, call_user_func_array('doSomething', array('param1' => 'something')); it doesn't return an error.

Can I make it force an error like, "This function should not accept parameters".

  • 写回答

3条回答 默认 最新

  • dpbfb7119 2015-03-07 16:29
    关注

    It's perfectly possible to send more parameters to a user-defined function than the function signature defines. That's because you can use additional code within your function to handle these, or simply ignore them.

    function doSomething(){
        if (func_num_args() > 0) {
            throw new Exception('Too many arguments');
        }
        ....
    }
    

    Use something like the above to test the arguments that have been passed to your function

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

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题