Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38321 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3150 invoked from network); 17 Jun 2008 11:35:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 11:35:02 -0000 X-Host-Fingerprint: 24.228.80.153 ool-18e45099.dyn.optonline.net Received: from [24.228.80.153] ([24.228.80.153:26660] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/57-61252-361A7584 for ; Tue, 17 Jun 2008 07:35:01 -0400 Message-ID: <22.57.61252.361A7584@pb1.pair.com> To: internals@lists.php.net Date: Tue, 17 Jun 2008 07:35:05 -0400 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041206 Thunderbird/1.0 Mnenhy/0.6.0.104 MIME-Version: 1.0 References: <77972256-ED0C-4FCE-8DEF-8283FE1BBFC5@roshambo.org> <28.6B.06776.09A76584@pb1.pair.com> <9b3df6a50806162327r52ae3ad9g65d56c0916571185@mail.gmail.com> <200806171121.03786.et@php.net> In-Reply-To: <200806171121.03786.et@php.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Posted-By: 24.228.80.153 Subject: Re: [PHP-DEV] deprecation status of $str{42} versus $str[42] From: edwardzyang@thewritingpot.com ("Edward Z. Yang") Stefan Walk wrote: > You're not learning from the mistakes of other languages (ruby in this case, > which removed Enumerable from String in 1.9) ... "foreach" makes no sense for > strings, because it's unclear what you want (with unicode terminology here, > as this is for php6): > "for each byte" "for each codeunit" "for each codepoint", or "for each line", > or ... You bring up a good point. However, as a counterpoint, Python does allow strings to be used as arrays: s = 'asdf' for c in s: print c In my opinion, it only makes sense for foreach to emulate the code snippet I posted above: for binary strings, that means byte-by-byte, and for Unicode strings, that means codepoint by codepoint. But as I said, it would be "neat." This is by no means an essential feature, and I probably wouldn't be able to use it anyway for BC concerns. > if you want to use foreach in your example, just do > foreach (str_split($str) as $value) { ... I would never do that, because it requires allocating an entire another PHP array, more than doubling memory usage, just to iterate across a string. If I'm doing this sort of heavy string processing, I probably need some semblance of performance. -- Edward Z. Yang GnuPG: 0x869C48DA HTML Purifier Anti-XSS Filter [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]