Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If we have the 3 classes and functions

  • foo::doSomething()
  • foo_subclass_one::doSomething()
  • foo_subclass_two::doSomething($input)

And I have an instance of one of these three, can I call $instance.doSomething($input)

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?

Thanks!

like image 954
Mike K Avatar asked May 18 '11 21:05

Mike K


1 Answers

Yes you can. Gather them with func_get_args()

like image 102
Jage Avatar answered Nov 15 '22 19:11

Jage