I thought I'd post a link to this PHP Variable Tests reference page. It's a great reference that's kept up to date with the current version of PHP. I use it sometimes when I'm waffling over what function to use to validate a variable.
Something I've noticed lately with the newer versions of PHP is that ctype_digit
no longer returns true
when you give it an empty string (ie. ctype_digit('')
). This is great, since I always thought that returning true on an empty string was counter-intuitive; by definition, it should only return true "if every character in $text
is a decimal digit", so if there's no characters, it can't be true. It's also great because that means that there's lots of places in some of my code where I can change
if (ctype_digit((string) $x) && $x != '')
to just
if (ctype_digit((string) $x))
,
which is cleaner and nicer.
It looks like they may have made this change back around PHP 5.1, but I never noticed it until I checked that variable reference page. Nice to see it!