On Sun, 11 Jul 2004, Marc Richards wrote: > 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);
This is starting to sound like the intval/floatval/strval functions that have been around for years and rarely used. We could simply soup these up a bit and thereby not add another function which could cause problems. Looks like it can be done without breaking backward compatibility too Of course, we would still need a version that didn't force the type, and in the case of the intval() function there is already a second optional arg whch specifies the base, so it isn't quite straightforward. So, perhaps introduce the value() function which doesn't do any type casting and enhance the intval(), strval() and floatval() functions to act like value() but cast appropriately unless the default arg is returned. To retain backward compatibility the intval() function's default arg would have to be after the optional base arg. -Rasmus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php