Christian Schneider <[EMAIL PROTECTED]> writes:

> Before it gets forgotten: I still think that
> $x = ifsetor(mixed var, mixed var [, ...]);
> with expressions in all parts is the way to go.
>
> Example usage:
> $a = ifsetor($_REQUEST['x'], $db->get('x'), 'default_x');
>
> And I also think that the name ifsetor has to be reevaluated :-)

This is the exact usage and meaning of the SQL function coalesce().  That may
be an appropriate name.
                       
>From the sqlite documentation:

    coalesce(X,Y,...)  Return a copy of the first non-NULL argument. If all
                       arguments are NULL then NULL is returned. There must be
                       at least 2 arguments.

And from the postgres documentation:

    COALESCE(value [, ...])

    The COALESCE function returns the first of its arguments that is not
    null. Null is returned only if all arguments are null. This is often
    useful to substitute a default value for null values when data is
    retrieved for display, for example:

    SELECT COALESCE(description, short_description, '(none)') ...

    Like a CASE expression, COALESCE will not evaluate arguments that are not
    needed to determine the result; that is, arguments to the right of the
    first non-null argument are not evaluated.

The coalesce() function is from the ANSI/ISO SQL:1999 standard, so its use has
been around for a while.

Derrell

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

Reply via email to