This is fine, all the calls to xyz that are lacking the final parameter still work (since it's optional.) But do this once or twice, and pretty soon you have function calls that look like this:
xyz('a', 2, $foo, '', '', '', '', '', '', $bar);
That's ugly and unnecessary, and leaves lots of room for bugs when you're writing functions that use the nth optional parameter in your function (since you have to count the number of blank spaces you need to leave.)
Additionally, what happens when all of your original, three-argument (a, 2, $foo) calls to xyz need to start passing an additional argument because of a change you couldn't predict when you first wrote your function?
Keyword arguments solve these problems. They're always optional - not just optional in that you can stick a '' or NULL in the spot where you would put a value in the function call. They're optional in that you can leave them out entirely. Because they're named, they can also be passed in any order. And, finally, you can add new keyword arguments at any time, and none of your current function calls will break.
If there's a way to do this in PHP (short of having the last argument be a hash) that I've missed, please let me know about it.
Daniel Cr
On Wed, 23 Jun 2004, Bert Slagter wrote:
Even after reading your message twice, I can't think of an example where this would be useful. Obviously, I don't understand your intention.
Could you give an example of a construction that is made possible by this feature (and thus would otherwise be impossible)?
Bert
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php