php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39533 ord() cast with (unsigned char), chr() with (signed char)
Submitted: 2006-11-16 14:54 UTC Modified: 2017-03-14 23:56 UTC
From: fred at cashette dot com Assigned: pollita (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.0 OS: *
Private report: No CVE-ID: None
 [2006-11-16 14:54 UTC] fred at cashette dot com
Description:
------------
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?revision=1.445.2.14.2.28&view=markup&sortby=date

PHP_FUNCTION(ord) ...
RETURN_LONG((unsigned char) Z_STRVAL_PP(str)[0]);

..

PHP_FUNCTION(chr) ...
temp[0] = (char) Z_LVAL_PP(num);

would not like use (unsigned char) in PHP_FUNCTION(chr) ? or opposite ?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 00:35 UTC] ajf@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2015-01-09 00:35 UTC] ajf@php.net
Making ord() produce a signed char would make it inconsistent across platforms, as whether char is signed or not varies. Plus, people are pretty used to it being unsigned.
 [2015-01-09 00:37 UTC] ajf@php.net
-Status: Wont fix +Status: Open
 [2015-01-09 00:37 UTC] ajf@php.net
Wait, I think I misunderstood. You want chr() to cast to unsigned char? There might be a case for that. Oops.
 [2017-03-14 23:56 UTC] pollita@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pollita
 [2017-03-14 23:56 UTC] pollita@php.net
ord() needs to return an unsigned 8bit value (uchar) for BC reasons (and because it's just consistent with \xHH and %HH notation as well as codepoint syntax.

chr() needs to cast to to char since PHP strings are c arrays of char.

Nothing to fix here.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC