ID:               18428
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Closed
 Bug Type:         Documentation problem
 Operating System: Linux
 PHP Version:      4CVS-2002-07-19
 New Comment:

While I accept the backwards-compatibility argument 
conditionaly, the rest of the reasoning, i.e. "can't see 
the contradiction here as in an empty string every of the 
0 charactetrs matches the criteriy ..." is hard to 
believe. 
 
If there is nothing, there is nothing to match. With the C 
versions of these functions, it is obviously not possible 
to run into this situation; essentially they _require_ a 
'string' that is one character long, taking a character 
argument. Therefore, these functions should have required 
that the string be at least one character long in the 
first place. It is unfortunate that what inconsistent 
behavior with the real ctype functions must be maintained 
for backwards compatibility, especially for an extension 
that is so young (it has only been a default option since 
4.2). If there were ever a time to correct its behavior, 
better sooner than later. 
 
I had included ctype_ equivalent functions in PEAR under 
DBA/ctype.php due to the fact that these functions are not 
commonly included with PHP installations. I wrote that 
exhibit what I feel is the correct behavior before 
noticing the ctype functions built-in to PHP. Should I  
now rewrite them so that they and are inconsistent with 
C's ctype functions but compatible with PHP's?


Previous Comments:
------------------------------------------------------------------------

[2002-07-19 06:01:35] [EMAIL PROTECTED]

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

------------------------------------------------------------------------

[2002-07-19 01:12:35] [EMAIL PROTECTED]

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


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to