On Dec 1, 2005, at 6:59 AM, Christian Schneider wrote:

Ron Korving wrote:
Named parameter example:

Your example misses the main advantage of named parameters IMHO: Sets of parameters you don't want to or can't explicitely list because they are not know yet.

  function adduser($params)
  {
if (!is_array($params)) throw new Exception('No named parameters'); if (!isset($params['username'])) throw new Exception('Missing parameter: username'); if (!isset($params['password'])) throw new Exception('Missing parameter: username');
    if (!isset($params['superuser'])) $params['superuser'] = false;
    // now do some stuff with $params
  }
adduser(array('username' => 'root', 'password' => 'abcdefg', 'superuser' => true));

This is not how we use named parameters at all. If you have a finite set of fixed parameters then positional parameters are working just fine.

Well, I wouldn't say that. The problem isn't that positional parameters don't work fine -- they do -- but that upon code inspection you don't know what those parameters are for unless you know the function/method API ahead of time. Sure, as you pointed out there are some juicy features you get with named parameters if you implement them throughly, but I still say its main selling point is that the calling code is its own API documentation.

Regards,

Jared

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to