|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-03-13 13:10 UTC] narf@php.net
-Status: Open
+Status: Wont fix
-Package: Feature/Change Request
+Package: *General Issues
[2017-03-13 13:10 UTC] narf@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 25 06:00:01 2025 UTC |
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.