Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53439 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54563 invoked from network); 20 Jun 2011 17:34:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 17:34:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=truth@proposaltech.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=truth@proposaltech.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain proposaltech.com does not designate 98.138.84.172 as permitted sender) X-PHP-List-Original-Sender: truth@proposaltech.com X-Host-Fingerprint: 98.138.84.172 smtp106.sbc.mail.ne1.yahoo.com Received: from [98.138.84.172] ([98.138.84.172:28928] helo=smtp106.sbc.mail.ne1.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/51-34681-0A48FFD4 for ; Mon, 20 Jun 2011 13:34:24 -0400 Received: from [192.168.2.102] (localhost [127.0.0.1]) by smtp106.sbc.mail.ne1.yahoo.com (8.14.4/8.14.4) with ESMTP id p5KHYKqF076958; Mon, 20 Jun 2011 10:34:21 -0700 (PDT) (envelope-from truth@proposaltech.com) To: Stas Malyshev Cc: "internals@lists.php.net" In-Reply-To: <4DFF7E2A.50506@sugarcrm.com> References: <1308584208.6296.9.camel@guybrush> <1308586150.6296.13.camel@guybrush> <1308589044.8394.27.camel@inspiron> <4DFF7E2A.50506@sugarcrm.com> Content-Type: text/plain; charset="ISO-8859-1" Date: Mon, 20 Jun 2011 10:34:20 -0700 Message-ID: <1308591260.8394.47.camel@inspiron> Mime-Version: 1.0 X-Mailer: Evolution 2.30.1.2 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: foreach() for strings From: truth@proposaltech.com (Todd Ruth) On Mon, 2011-06-20 at 10:06 -0700, Stas Malyshev wrote: > Hi! > > On 6/20/11 9:57 AM, Todd Ruth wrote: > > Iterators are nice. Having a "text_string_to_array" function > > would also be fine. For example: > > > > $s = 'hello'; > > foreach (text_string_to_array($s) as $x) { > > var_dump($x); > > } > > > text_to_array($s) == str_split($s, 1) Does that have approximately the same performance as marking the string as being OK to use as an array? For example, $s = file_get_contents($big_file); foreach (str_split($s, 1) as $x) { f($x); } Are there performance issues with the above compared to: $s = file_get_contents($big_file); foreach (text_string_to_array($s) as $x) { f($x); } assuming text_string_to_array could be implemented as marking the string OK to use as an array. Again, I don't know enough about the internals. I'm just imagining a significant difference for very long strings between: $a1 = text_to_array('hello'); and $a2 = array('h','e','l','l','o'); $a1 and $a2 could act identically until a set occurred. For example, "$a1['key'] = 5;" would first trigger $a1 becoming just like $a2 so that the set could take place. Any string that has not been hit with text_string_to_array would lead to all the usual error messages some of us know and love and any string that has been hit with text_string_to_array would allow all the fancy features some people are seeking. I'm trying to find a way to please the people that want strings to act like arrays without ruining the day for those of us who are glad strings don't act like arrays. - Todd