This doesn't help get rid of your ternary operator, but I find for those times when you absolutely, positively have to have a valid non- negative integer ctype_digit() is the way to go. Both is_numeric and intval accept the plus sign, the minus sign, a decimal point, the letter 'e', and strings in hexidecimal form (intval will turn any string with leading digits into an integer, actually). There are some issues with casting to an integer, also -- this, for example, gives somewhat surprising results:

php -r 'echo (int) 12e90;'

Which is great, if that's what you're looking for, but sometimes you already know that the incoming item should be an actual non-negative integer and you just want to scrub it to avoid injection attacks or random db breakage. Something like this might provide a minor upgrade:

$page_index = ctype_digit($_GET['page']) ? $_GET['page'] : $default_page;


dann
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to