RE: [PHP-DEV] foreach() for strings
| From: | John Crenshaw | Date: | Mon, 20 Jun 2011 16:15:36 +0000 |
| Subject: | RE: [PHP-DEV] foreach() for strings | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53424@lists.php.net to get a copy of this message | ||
> From: Ilia Alshanetsky [mailto:ilia@prohost.org]
>
> As long as it works on a premise that a "string" is a byte array and
> each element represents 1 byte, +1 from me.
Code written on this premise is almost always bug central when people finally get around to
realizing why they really do need to support wide characters (and everybody does, because people
like to paste stuff containing non-break-spaces, and decorative quotes). I really don't think
this single byte character mentality should be encouraged.
Also, how do you think this will work with the Unicode conversion in PHP 6? Guaranteed, this will
break stuff. Some people will have written code to iterate characters, assuming single byte
characters, some people will have written code ACTUALLY intending to iterate as a byte array. Sadly,
we can almost certainly assume that the single byte characters assumption (which is wrong) will also
be, by far, the most common. Supporting that most common case when moving to PHP 6 would require
breaking the binary case (which was the only properly written code in the first place.) On the other
hand, supporting the binary case means breaking the most common case.
John Crenshaw
Priacta, Inc.