Here's a link to my implementation of named parameters in PHP:
I did it a few years ago for the mysql driver and then when mysqli came out I made another version for mysqli. The source for both is linked in that URL.
Please share it with your audience or use it yourself!
|2010-11-01 22:11:01 - In reply to message 1 from Jonathan Buhacoff|
|There seems to be some confusion. Named parameters are for PHP functions, not for database prepared statements.|
In the show notes there is link to the discussion in the PHP internales mailing list. You may want to read it to understand better what that is:
|2010-11-01 23:29:35 - In reply to message 2 from Manuel Lemos|
|Yeah, I mentioned it because positional parameters for database queries are even more cumbersome because you have to do everything twice... the "?" in the query and then the value afterwards. |
I thought it was a little relevant.
Anyway the Perl crowd has been talking about named parameters for a few years, there's a lot we could learn from their discussions.
Regarding functions, my standard for functions that accept a lot of parameters has been to just pass an array, like f(array("p1"=>"value1",...)) and that's been working out alright. It would be nice to have something a little cleaner.
I'd only switch to using a built-in named parameters syntax if it allowed me to get rid of all the quotes, so I could write f(p1=>"value1",key=>"value",count=>5) and notice how some of those are reserved keywords but would work ok in my hypothetical special context there, because if I meant to call the count function I would have written count() or count($array).
My 2 cents.
|2010-11-01 23:31:58 - In reply to message 3 from Jonathan Buhacoff|
|Right, it was considered in PHP too many years ago but it was rejected then for adding so claimed "unnecessary complexity".|
Anyway, the feature request keeps coming. Soon or later somebody will submit a patch and the discussion continues.