Just to throw in my two cents since every one else has (not that my 2
cents is worth anything more than just that), but isn't it as easy as
doing something like the following:

(using pseudo example from above)

function db_connect($params) {
    $host = 'localhost';
    $user = 'root';
    $password = '';
    $port = 3301;
    extract($params, EXTR_OVERWRITE);
    // ... more code here
}

This covers the default parameters in a clean fashion which is easy to
understand and should be readable to anyone who knows PHP in even the
slightest fashion. Now to the issue of type hinting, it's as simple as
doing something like the following:

if(!($obj instanceOf ClassName)) {
   throw new Exception();
}

Then you have complete control of how the error is handled (be it
exceptions, trigger_error(), etc). To me, it seems the options are a
LOT more flexible using array syntax than using actual named
parameters, but maybe that's just me. To each their own, but if it
were me, it seems the above not only is easier to use / read, but also
guaranteed to work on almost all versions of PHP (at least in the case
of the first code snippet).


--
---------------------------
Jeremy Johnstone
http://www.jeremyjohnstone.com
[EMAIL PROTECTED]

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

Reply via email to