你能传递比函数预期更多的参数吗? [英] Can you pass more parameters than a function expects?
问题描述
如果您有两个类扩展了同一个基类,并且需要让其中一个类覆盖一个函数以获取额外的参数.在任一类上调用函数时总是传递附加参数可以吗?
If you have two classes extending the same base class, and need to make one of them override a function to take an additional parameter. Is it okay to always pass the additional parameter when calling the function on either class?
一些伪代码来帮助演示...
A bit of pseudo-code to help demonstrate...
如果我们有 3 个类和函数
If we have the 3 classes and functions
- foo::doSomething()
- foo_subclass_one::doSomething()
- foo_subclass_two::doSomething($input)
我有这三个之一的实例,我可以调用$instance.doSomething($input)
And I have an instance of one of these three, can I call $instance.doSomething($input)
我-认为- foo 和 foo_subclass_one 会忽略附加参数而 foo_subclass_two 会使用它.这样对吗?如果我有很多子类并且真的想避免接触 10 多个文件,有没有更好的方法可以做到这一点?
I -think- what happens is that foo and foo_subclass_one would just ignore the additional parameter and foo_subclass_two would make use of it. Is this correct? Is there a better way I can do this if I have a lot of subclasses and really want to avoid touching 10+ files?
谢谢!
推荐答案
是的,你可以.使用 func_get_args()
Yes you can. Gather them with func_get_args()
这篇关于你能传递比函数预期更多的参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!