Re: Re: Named arguments revisited

From: Date: Thu, 12 Jan 2006 13:33:21 +0000
Subject: Re: Re: Named arguments revisited
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-21485@lists.php.net to get a copy of this message
Jason Garber wrote:
Here is a coding idea for you, in case you hadn't considered it... function highlight($text=NULL, $needle=NULL, $strip_links=NULL, ...) {
     is_null($text) && $text = SOME DEFAULT VALUE;
     is_null($needle) && $text = SOME DEFAULT VALUE;
     is_null($strip_links) && $text = SOME DEFAULT VALUE;
     ...
}
We use function highlight($p = array()) { $p += array( # Also serves as documentation 'text' => SOME_DEFAULT_VALUE, 'needle' => SOME_DEFAULT_VALUE, 'strip_links' => SOME_DEFAULT_VALUE, ... ); } ... $highlight(array('strip_links' => true)); in cases just like this. <shameless_plug> Plus the patch from <http://cschneid.com/php> to get $highlight('strip_links' => true); </shameless_plug> If named parameters for PHP are considered in the future then my main wish would be that there is a catch-all array receiving all the non-assignable parameters. - Chris

« previous php.internals (#21485) next »