PHP Classes

named parameters in php

Recommend this page to a friend!

      PHP Classes blog  >  Unusual Site Speedup ...  >  All threads  >  named parameters in php  >  (Un) Subscribe thread alerts  
Subject:named parameters in php
Summary:presenting my implementation from a couple of years ago
Messages:4
Author:Jonathan Buhacoff
Date:2010-11-01 17:40:31
Update:2010-11-01 23:31:58
 

  1. named parameters in php   Reply   Report abuse  
Picture of Jonathan Buhacoff Jonathan Buhacoff - 2010-11-01 21:14:45

Here's a link to my implementation of named parameters in PHP:

buhacoff.net/software/php-mysql/


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!

  2. Re: named parameters in php   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 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:

marc.info/?l=php-internals&m=128716 ...

  3. Re: named parameters in php   Reply   Report abuse  
Picture of Jonathan Buhacoff Jonathan Buhacoff - 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.

  4. Re: named parameters in php   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 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".

php.net/~derick/meeting-notes.html# ...

Anyway, the feature request keeps coming. Soon or later somebody will submit a patch and the discussion continues.