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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php