Req #43950 [Opn->Wfx]: Char-wise v byte-wise string indexing
| From: | narf@php.net | Date: | Mon, 13 Mar 2017 13:10:24 +0000 |
| Subject: | Req #43950 [Opn->Wfx]: Char-wise v byte-wise string indexing | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207814@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=43950&edit=1
ID: 43950
Updated by: narf@php.net
Reported by: jrf_temp_2003 at comcast dot net
Summary: Char-wise v byte-wise string indexing
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Linux
PHP Version: 5.2.5
Block user comment: N
Private report: N
New Comment:
mbstring.func_overload is deprecated in PHP 7.2 and will be removed in 8.0.
https://wiki.php.net/rfc/deprecations_php_7_2#mbstringfunc_overload
Previous Comments:
------------------------------------------------------------------------
[2008-01-27 23:17:34] jrf_temp_2003 at comcast dot net
Description:
------------
When I "upgraded" to multibyte char encoding and functions, I discovered that I could no
longer rely on $s{strlen($s)-1} to access the last character in a string. Strlen correctly counted
only whole chars, but the indexing came up short by the number of double-wide chars in the string
and hit the wrong char. I could (and did) patch my scripts with rtrim, but others may not be so
lucky. I had an idea...
Suggestion:
Some time ago, square brackets were deprecated in favor of curly braces for individual char access
in a string. Could both be employed, each for a different purpose? Could curly braces to be used for
multibyte-sensitive indexing? Could square brackets, as always, offer simple byte-wise access?
Reproduce code:
---------------
// After a loop chains field names + commas...
$sql{strlen($sql)-1} = ' '; // Replace last trailing comma with a space
$sql.= $where_clause;
// Because my aim was at the very end of a string, rtrim could solve
// my problem. Less specialized cases would not be so easy.
Expected result:
----------------
// There should be two chars in quotes and no comma between the quoted
// value and WHERE
... x="**" WHERE ...
Actual result:
--------------
// Two mb chars elsewhere in string displaced the substitution
// by two places to the left, wiping out a quoted char and leaving
// the comma:
... x="* ",WHERE ...
// Could it be possible for $s{} to index by mb chars? If so, then
// $s[] could be resurrected to index by bytes as both do currently.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=43950&edit=1