From: vesely at tana dot it
Operating system:
PHP version: 4.3.2
PHP Bug Type: *Languages/Translation
Bug description: Character type functions fail on negative chars

Description:
------------
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); \



Ciao
Ale
---
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:
---------------
<?php
$ctype_funcs = array(
"alnum", "alpha", "cntrl", "digit",
"graph", "lower", "print", "punct",
"space", "upper", "xdigit");

$failed = 0;

reset($ctype_funcs);
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));
next($ctype_funcs);
}
print "$failed";
?>

Expected result:
----------------
0

Actual result:
--------------
817

--
Edit bug report at [url]http://bugs.php.net/?id=25745&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=25745&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=25745&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=25745&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=25745&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=25745&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=25745&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=25745&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=25745&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=25745&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=25745&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=25745&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=25745&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=25745&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=25745&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=25745&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=25745&r=float[/url]