NYCPHP Meetup

NYPHP.org

[nycphp-talk] ctype_digit in PHP 5.1.x

Scott Mattocks scott at crisscott.com
Fri Dec 2 11:32:56 EST 2005


Chris Shiflett wrote:
> Scott Mattocks wrote:
>> Anyway, the problem is with ctype_digit returning true for null
>> strings.
> 
> There is no such thing as a null string, because null is not a string. I 
> think you mean the empty string, based on your example:

Yes. I meant empty string. Sorry.

> Why would this be considered a bug?
> 
> The ctype_digit() function returns true if every character in a string 
> is a digit. The length of the string seems like a separate criterion.

It would be a bug because it doesn't function as one would expect. The 
manual says, " Returns TRUE if every character in text is a decimal 
digit, FALSE otherwise." Since there are no characters, they cannot be 
decimal digits. Therefore, I would expect the "FALSE otherwise" to kick 
in. If it said, "Returns FALSE if the string contains non-decimal 
characters" I might agree with you. It may just be semantics, but do you 
really expect ctype_digit('') to return TRUE?

Anyway, I decided not to be such a dummy and just downloaded the Windows 
version. In 5.1.1 (on Windows at least), ctype_digit('') returns false.

Thanks,
Scott



More information about the talk mailing list