Re: deprecation status of $str{42} versus $str[42]
| From: | Stefan Walk | Date: | Tue, 17 Jun 2008 09:21:03 +0000 |
| Subject: | Re: deprecation status of $str{42} versus $str[42] | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38316@lists.php.net to get a copy of this message | ||
On Tuesday 17 June 2008 08:27:37 Arvids Godjuks wrote:
> 2008/6/16 Edward Z. Yang <edwardzyang@thewritingpot.com>:
> > PHP userland code may not treat strings as first class arrays, but
> > that's certainly how they are represented internally.
> >
> > Anyway, it would be neat if we could get that foreach syntax to work. I
> > get sick of for($i = 0, $c = strlen($str); $i < $c; $i++) very quickly.
>
> Totaly agree, the best example from the whole thread
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 ... if you want to use foreach in your example, just do
foreach (str_split($str) as $value) { ...
Regards,
Stefan