Bug #18428 Updated: ctype functions return TRUE on zero-length strings

From: Date: Fri, 19 Jul 2002 10:01:37 +0000
Subject: Bug #18428 Updated: ctype functions return TRUE on zero-length strings
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-14618@lists.php.net to get a copy of this message
ID: 18428 Updated by: hholzgra@php.net Reported By: busterb@mail.utexas.edu -Status: Open +Status: Closed -Bug Type: Strings related +Bug Type: Documentation problem Operating System: Linux PHP Version: 4CVS-2002-07-19 New Comment: an empty string is a string ;) the documentation says: " When called with a string argument they will check every character in the string and will only return TRUE if every character in the string matches the requested criteria. " can't see the contradiction here as in an empty string every of the 0 charactetrs matches the criteriy ... will add a note about that in the documentation, but the behaviour will not change for backwards compatibility reasons Previous Comments: ------------------------------------------------------------------------ [2002-07-19 01:12:35] busterb@mail.utexas.edu The PHP ctype functions return TRUE when passed a zero length string. This is incorrect behavior; see the documentation for the contradiction. This is not an issue with the C ctype functions, since they deal with characters, which cannot be zero-length. The following patch corrects this behavior --- ctype.c 2002-07-18 23:58:02.000000000 -0500 +++ ctype_fixed.c 2002-07-18 23:57:48.000000000 -0500 @@ -102,8 +102,11 @@ { \ char *p; \ int n, len; \ - p=Z_STRVAL_P(c); \ len = Z_STRLEN_P(c); \ + if (!len) { \ + RETURN_FALSE; \ + } \ + p = Z_STRVAL_P(c); \ for(n=0;n<len;n++) { \ if(!iswhat(*p++)) RETURN_FALSE; \ } \ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18428&edit=1

« previous php.bugs (#14618) next »