Hi.

Could somebody please point me in the right direction with regards to having an instance of a class passed into a function in another class, whereby that particular parameter is optional?

I have usually used $param="" with optional parameters, but is this the best way when dealing with objects? Would $param=new myCls be better?

I am at a bit of a loss. As well as wanting to know the answer to my specific problem I would like to/need to know more around the subject too, so does anybody know where I can read up on this sort of thing? Am looking for something that isnt too involved with the begginer side, but isnt too advance either.

Thanks.
K.

    It depends what you want to happen when the argument is left blank. Are you going to set it to a default object or just not use anything? setting some like $param=new myCls would be considered deep coupling and should be avoided.

    I guess the biggest question is however. If your function was setup to accept an instance of class A by default, and someone tried to pass it an instance of class B would your function still work?

      Write a Reply...