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
------------------------------
<?php
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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php