Re: Re: Named arguments revisited

From: Date: Fri, 13 Jan 2006 12:52:30 +0000
Subject: Re: Re: Named arguments revisited
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-21514@lists.php.net to get a copy of this message
I think everybody should be open to a new way of dealing with functions. The advantages apply to many many functions. Take for example: mysqli mysqli_connect ( [string host [, string username [, string passwd [, string dbname [, int port [, string socket]]]]]] ) It would be nice to be able to do $conn = mysqli_connect(host: $host, port: $port); without having to worry about anything else than the parameters I care about. It's a new way of doing things, and that may be scary, but think how useful this can be for programmers. When you call a function, the order in which you present the function parameters is never interesting, except for a few rare cases like printf(). But unlike printf(), the functioning of a strpos() function doesn't require a certain order in parameters. It requires a needle and a haystack. In any situation, including function parameters, I consider requiring a certain order where it's not needed an overspecification. Just like this is an overspecification: for ($i=0; $i < count($array); $i++) echo $array[$i]; compared to: foreach ($array as $element) echo $element; because you simply don't need $i. Named parameters are, like foreach, a means to reduce overspecification. - Ron "Lukas Smith" <lsmith@php.net> schreef in bericht news:43C79EE0.909@php.net... > Hartmut Holzgraefe wrote: >> Lukas Smith wrote: >>> Its sole purpose is to deal with situations where you have a >>> considerable number of parameters. >> >> well, i for one would love to write something like >> >> $pos = strpos(haystack=$str, needle="foobar"); >> >> instead of looking up parameter orders all the time :) > > I would specifically not go there. This would create the inconsistant > situation you describe. It would be fixing one past mistake with a new > evil. > > As noted the cases are not as wide as most people make it sound, also its > not really related to this discussion. > > regards, > Lukas

« previous php.internals (#21514) next »