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
Make optionalparameters in your own defined class [ANSWERED]
Moderator: General Moderators
- christian_phpbeginner
- Forum Contributor
- Posts: 136
- Joined: Sat Jun 03, 2006 2:43 pm
- Location: Java
Make optionalparameters in your own defined class [ANSWERED]
Last edited by christian_phpbeginner on Fri Aug 11, 2006 5:55 pm, edited 1 time in total.
-
jamiel
- Forum Contributor
- Posts: 276
- Joined: Wed Feb 22, 2006 5:17 am
- Location: London, United Kingdom
You need to specify a default value if you want it to be optional.
In that function you don't have to specify optional, but it will default to null.
Code: Select all
function foo($required, $optional = null) { }- christian_phpbeginner
- Forum Contributor
- Posts: 136
- Joined: Sat Jun 03, 2006 2:43 pm
- Location: Java
hi jamiel...jamiel wrote:You need to specify a default value if you want it to be optional.
In that function you don't have to specify optional, but it will default to null.Code: Select all
function foo($required, $optional = null) { }
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