Re: ctype second opinions

From: Date: Sun, 21 Jul 2002 07:28:44 +0000
Subject: Re: ctype second opinions
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-7813@lists.php.net to get a copy of this message
On Sun, 21 Jul 2002, Stig S. Bakken wrote: > On Fri, 19 Jul 2002, Pierre-Alain Joye wrote: > > > On Fri, 19 Jul 2002 08:41:53 -0500 (CDT) > > Brent Cook <busterb@mail.utexas.edu> wrote: > > > > > Dear all, > > > > > > I would like your opinion, please. I'm currently arguing a bug in the > > > PHP database, http://bugs.php.net/bug.php?id=18428, > > > and basically feel > > > that I have made the correct choice, while the PHP developer feels > > > otherwise. > > > > > > The ctype functions in PHP currently return TRUE on an empty string. For > > > instance, ctype_alpha('a') == TRUE, ctype_alpha('1') == FALSE, > > > ctype_alpha('') == TRUE. I argued that since no characters in an empty > > > string match the criteria, an empty string should return FALSE. The > > > developer argued that "in an empty string every of the 0 charactetrs > > > matches the (criteria)", so it should return TRUE. > > > > afaik, ctype_alpha checks only the type, returning true if the param is > > an alhatype. An empty string is an alpha. That s a fact. > > You're pulling Brent's leg now right? Right? > > - Stig Through careful application of the Heisenberg uncertainty principal, which states: "the more precicely the data type is determined, the less precicely the contents are known", we were able to determine that a null (empty) string is in a simultaneous state between containing every possible character and containing none. Unlike Schoedinger, even through direct observation are we unable to force an empty string to 'decide' a state. Simply put, take strings $a = "alpha", $b = "12345" and $c = ''. By definition: ctype_alpha($a) == TRUE, ctype_alpha($b) == FALSE and ctype_digit($a) == FALSE, ctype_digit($b) == TRUE and ctype_digit($a.$b) == FALSE, ctype_digit($a.$b) == FALSE .. and so on for other ctype_ functions Therefore $a is alpha and only alpha and $b is numeric and only numeric (other cases left as an exercise for the reader) However: ctype_alpha($a.$c) == TRUE, so ctype_alpha($c) must be true Yet: ctype_digit($a.$b) == TRUE, so ctype_digit($c) must be true also. Therefore, $c is both alpha and digit. You could also interpret this leads to a contradiction, i.e. reductio ad absurdum, and thus claim that the moon is made of green cheese. That would of course be irrational, since every one knows that it is actually of fine swiss due to its glossy finish and nutty flavor. PHP: proudly obeying the laws of quantum mechanics since at least last April :) - Brent

« previous php.pear.dev (#7813) next »