Page 1 of 1
Make optionalparameters in your own defined class [ANSWERED]
Posted: Fri Aug 11, 2006 7:41 am
by christian_phpbeginner
Hi, I've seen some or more functions in PHP which have optional parameters. And this has made me wondered, could I define optional parameters in my own class ?
Thank you,
Chris
Posted: Fri Aug 11, 2006 7:45 am
by jamiel
You need to specify a default value if you want it to be optional.
Code: Select all
function foo($required, $optional = null) { }
In that function you don't have to specify optional, but it will default to null.
Posted: Fri Aug 11, 2006 5:53 pm
by christian_phpbeginner
jamiel wrote:You need to specify a default value if you want it to be optional.
Code: Select all
function foo($required, $optional = null) { }
In that function you don't have to specify optional, but it will default to null.
hi jamiel...
Is it that simple ? Silly me !.....thanks for the reply, now I know how to declare an optional parameter inside a function in my own class.
Thanks a lot,
Chris