Marc Richards wrote:
I don't think a function named param() really fits, but I do like the idea of adding a type check (or in the case of PHP a type cast) to the function.
$level = (int) (isset($_SESSION['level']) ? $_SESSION['level'] : (isset($_REQUEST['level']) ? $_REQUEST['level'] : 1))
becomes
$level = value($_SESSION['level'], $_REQUEST['level'], 1, INT);
P.S. Aside from simply moving the type cast into the function, this would also avoid doing the cast on the default variable, which could be particularly useful if you want $level to be NULL...in which case it might be better to switch the order of the last two params since INT is "bound to" the variables, not the default
$level = value($_SESSION['level'], $_REQUEST['level'], INT, 1);
or
$level = value($_SESSION['level'], $_REQUEST['level'], INT, NULL);
or
$level = value($_SESSION['level'], $_REQUEST['level'], INT);
Marc
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php