Re: Re: Named arguments revisited

From: Date: Thu, 19 Jan 2006 04:09:19 +0000
Subject: Re: Re: Named arguments revisited
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-21574@lists.php.net to get a copy of this message
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.
I think you should use EXTR_IF_EXISTS instead of EXTR_OVERWRITE. I guess you don't want undefined arguments to be defined by the user. Just adding my 2 cents too.

« previous php.internals (#21574) next »