Bug #70591 [Nab]: ord() no longer yields correct results consistently

From: Date: Sun, 27 Sep 2015 00:37:14 +0000
Subject: Bug #70591 [Nab]: ord() no longer yields correct results consistently
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196264@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70591&edit=1

 ID:                 70591
 Updated by:         requinix@php.net
 Reported by:        slevy1 at pipeline dot com
 Summary:            ord() no longer yields correct results consistently
 Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   n/a
 PHP Version:        7.0.0RC3
 Block user comment: N
 Private report:     N

 New Comment:

https://wiki.php.net/rfc/default_encoding,
by the way


Previous Comments:
------------------------------------------------------------------------
[2015-09-27 00:36:02] requinix@php.net

The default character encoding, which your calls to mb_strcut() will be using, changed to be UTF-8
in PHP 5.6.

https://3v4l.org/YE6I9

------------------------------------------------------------------------
[2015-09-27 00:10:39] slevy1 at pipeline dot com

Description:
------------
I used ord() in combination with mb_strcut() to obtain the byte values of a multibyte char utf-8
encoded.  This used to work in PHP 5.4.8 - 5.5.29.  But in PHP5.6-PHP7.00rc3 it doesn't work
any more :(

Test script:
---------------
<?php 


$str = "♥"; // 3 byte values per above

var_dump( ord(mb_strcut($str, 0, 1) )); 
var_dump( ord(mb_strcut($str, 1, 1) )); 
var_dump( ord(mb_strcut($str, 2, 1) ));

see live code: https://3v4l.org/OoFus

Expected result:
----------------
I expected the var dumps to produce decimal results as follows:

 226 
 153
 165

Actual result:
--------------
0
0
0


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



--
Edit this bug report at https://bugs.php.net/bug.php?id=70591&edit=1


Thread (5 messages)

« previous php.bugs (#196264) next »