On Fri, 13 Jan 2006, Ron Korving wrote: > 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.
You do know that that means that we have to consistently name all parameters to our 4000+ functions, right? Besides that road block, I don't see how: mysqli_connect(host: $host, port: $port); differs from: mysqli_connect( array( 'host' => $host, 'port' => $port ) ); (except that it's a bit more to type). If you're designing an API of your own you can easily design it in such a way that you don't have that many parameters anyway. A specific class accepting a lot of parameters can easily set them as default: <?php class ezcTranslationTsBackend { private $tsLocationPath; private $tsFilenameFormat = '[LOCALE].xml'; function __construct( $location, array $options = array() ) { $this->setOptions( array( 'location' => $location ) ); $this->setOptions( $options ); } public function setOptions( array $configurationData ) { foreach ( $configurationData as $name => $value ) { switch ( $name ) { case 'location': if ( $value[strlen( $value ) - 1] != '/' ) { $value .= '/'; } $this->tsLocationPath = $value; break; case 'format': $this->tsFilenameFormat = $value; break; default: throw new ezcBaseSettingNotFoundException( $name ); } } } ?> You can even easily verify the parameters that you're passing for ranges etc. This is a cleaner API as it's easier to read, and definitely not harder to write. On top of that you get the benefit of value/range checking. The usage is then simply: <?php $a = new ezcTranslationTsBackend( 'files' ); ?> or: <?php $a = new ezcTranslationTsBackend( 'files', array( 'format' => "test-[LOCALE].xml' ) ); ?> or: <?php $a = new ezcTranslationTsBackend( 'files' ); $a->setOptions( array( 'format' => "test-[LOCALE].xml' ) ); ?> > 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. I would rather think it's less obvious about what is going on. You should always care in which order you pass arguments to normal functions, as otherwise you're getting inconsistencies in its usage all through your application. And I would not be happy to see: $blah = strpos( haystack: $string; needle: 'F' ); instead of: $blah = strpos( $string, 'F' ); regards, Derick -- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php