Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23152 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19108 invoked by uid 1010); 4 May 2006 19:38:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 19093 invoked from network); 4 May 2006 19:38:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2006 19:38:53 -0000 X-PHP-List-Original-Sender: dante@vocalspace.com X-Host-Fingerprint: 69.56.193.72 fox02.stravio.com Linux 2.5 (sometimes 2.4) (4) Received: from ([69.56.193.72:55358] helo=fox02.stravio.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 29/17-63443-D485A544 for ; Thu, 04 May 2006 15:38:53 -0400 Received: from [127.0.0.1] (unknown [66.243.31.162]) by fox02.stravio.com (Postfix) with ESMTP id E138826C33E; Thu, 4 May 2006 14:38:45 -0500 (CDT) Message-ID: <445A5840.2050000@vocalspace.com> Date: Thu, 04 May 2006 14:38:40 -0500 User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 To: "D. Dante Lorenso" Cc: dante@lorenso.com, internals@lists.php.net References: <44584619.60400@lorenso.com> <44591E27.4030005@vocalspace.com> In-Reply-To: <44591E27.4030005@vocalspace.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Specification for function filled() :: was ifsetor/coalesce From: dante@vocalspace.com ("D. Dante Lorenso") The default value for 'filled()' if all values test TRUE for empty() should be FALSE, not NULL. This is more consistent with the return values of empty(). Since filled() returns the first non-empty() value in the list of parameters provided, it works well when cast into a boolean context because the non-empty() value should evaluate as TRUE. Example: filled("testing") // returns testing if (filled("testing")) {} // true filled(87) // returns 87 (boolean) filled(87) // true $x["apple"] = "42"; filled($x["apple"]) // returns 42 filled($x["pear"]) // returns false if (filled($x["apple"]) !== false) {} // true if (filled($x["pear"]) !== false) {} // false Just wanted to chime in with an update in case 'filled()' can actually be considered. I'd like everyone to consider this one function to be evaluated on it's merits alone and apart from any other functions which also might be wanted. filled() is the opposite of empty() and is not dealing with tests for 'isset()'. Another function should be proposed to solve that problem if it would still be needed after filled() is implemented. Do I have any power to call a vote on this? Dante D. Dante Lorenso wrote: > Dear Internals, > > I'd like a white bikeshed, but until you can decide on a color, how > about we just build the bikeshed already. Please consider the > following specification: > > ========== 8< ==================== 8< ==================== 8< ========== > > filled > > (PHP 5.2.0) > > filled - Find first non-empty value in a variable list where empty() > evaluates as FALSE. > > Description > ------------------------------ > > mixed filled ( mixed varname [, mixed ...] ) > > filled() takes a variable number of parameters. For each of these, > *filled()* looks for a variable where !empty( varname ) evaluates as > TRUE. It returns the first non-empty value or NULL if all values are > empty(). > > Note: filled() only checks variables as anything else will result in a > parse error. In other words, the following will not work: > filled(trim($name)). > filled() is the opposite of empty(), and no warning is generated > when any one of the variables is not set. > > Return Values > ------------------------------ > > Returns first non-empty() value. > > If all values are empty(), returns NULL. > > Example > ------------------------------ > echo filled($x["somekey"], $_GET["getkey"], $default, "example"); > echo filled("yes"); // prints yes > filled(false); // returns NULL > echo filled($x["apple"], $y, "banana"); // prints banana > $y = "cat"; > echo filled($x["apple"], $y, "banana"); // prints cat > $x["apple"] = "pear"; > echo filled($x["apple"], $y, "banana"); // prints pear > unset($x["apple"]); > echo filled($x["apple"], $y, "banana"); // prints cat > ?> > > See also empty() > > ========== 8< ==================== 8< ==================== 8< ========== > > Dante >