Re: PHP 5.1

From: Date: Tue, 14 Jun 2005 04:37:37 +0000
Subject: Re: PHP 5.1
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-16649@lists.php.net to get a copy of this message
Ondrej and Jason, Just pondering the proposed coalesce() variants in the context of Ondrej's scenario I came upon two thoughts. I forgot to mention the nice single parameter case of a coalesce() function like this, which would return null if not set: $x = coalesce($REQUEST['x']); Also, the same characteristics could be easily preserved, as far as warnings and errors, by not passing any unset variables to the callback in a ucoalesce() function call: $x = ucoalesce("is_number", $REQUEST['x']); With that assertion, is_number() would only be called if the request variable were set, otherwise returning null, modeling the ternary expression you included, Ondrej. Thanks, -Noah On Jun 14, 2005, at 12:08 AM, Ondrej Ivanič wrote:
Jason Garber wrote:
ifsetor is NOT input filtering, it is not a complex, general purpose
stuff like 'ifsetof()' is good when is use as:
$x = ifsetor($ANY_var, 'Default Value');
but too many times I need additional checks like this: $x = isset($_REQUEST['x']) && is_number($x) ? $_REQUEST['x'] : null; It's possible to add additional third parameter to ifsetof() ? ifsetof(variable, expression [, callback]) callback is a function which take one argument (value of variable) and return true or false. If return false 'expression' will be return from ifsetor(). Usage: $x = ifsetor($_REQUEST['x'], null, 'is_number');
It needs to be fast, and simple.
Hm... It's simple, but It's not very clean at first look. What's your opinion? --Ondrej Ivnaic (ondrej@kmit.sk) --PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#16649) next »