|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25745 Character type functions fail on negative chars
Submitted: 2003-10-03 11:41 UTC Modified: 2003-10-03 12:13 UTC
From: vesely at tana dot it Assigned: moriyoshi (profile)
Status: Closed Package: *Languages/Translation
PHP Version: 4.3.2 OS: Solaris 8 (SPARC)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: vesely at tana dot it
New email:
PHP Version: OS:


 [2003-10-03 11:41 UTC] vesely at tana dot it
The upper half of the codes are badly reported, e.g
ctype_alpha("?") returns true even under C locale.

As a workaround one may call ctype_alpha(ord("?")),
which works correctly.

Alternatively, the following patch fixes that:

--- php-4.3.2/ext/ctype/ctype.c%        2003-10-03 13:13:46.870457000 +0200
+++ php-4.3.2/ext/ctype/ctype.c 2003-10-03 13:13:46.880455000 +0200
@@ -100,7 +100,7 @@
                RETURN_BOOL(iswhat(Z_LVAL_P(c))); \
        case IS_STRING: \
                { \
-                       char *p; \
+                       unsigned char *p; \
                        int n, len; \
                        p=Z_STRVAL_P(c); \
                        len = Z_STRLEN_P(c); \

below I list character type functions for
easing bug searches

ctype_alnum ctype_alpha ctype_cntrl ctype_digit
ctype_graph ctype_lower ctype_print ctype_punct
ctype_space ctype_upper ctype_xdigit 

Reproduce code:
        $ctype_funcs = array(
        "alnum", "alpha", "cntrl", "digit",
        "graph", "lower", "print", "punct",
        "space", "upper", "xdigit");
        $failed = 0;

        while ($name = current($ctype_funcs)) {
                $test = "\$failed += (
                        (ctype_$name(%d) ? 1 : 0) !=
                        (ctype_$name(chr(%d)) ? 1 : 0)
		) ? 1 : 0;";
                for ($i = 0; $i < 256; ++$i)
                        eval(sprintf($test, $i, $i));
        print "$failed";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-03 11:59 UTC] vesely at tana dot it
I got 817 compiling with gcc 3.2 on sun sparc solaris8,
depending on the __ctype table, results may vary.
 [2003-10-03 12:13 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 20 06:03:34 2022 UTC