I also thought about similar approach for "object by value case".
I think, first we should accept the proposed in thic RFC behavior. It's
consistent, and more comatible with PHP5. Later, if we decide to merge
zend_array with HashTable we may try to change it.

Thanks. Dmitry.
On Jan 31, 2015 4:18 PM, "Nikita Popov" <nikita....@gmail.com> wrote:

> On Fri, Jan 30, 2015 at 8:23 AM, Dmitry Stogov <dmi...@zend.com> wrote:
>
>> Hi,
>>
>> I'd like to start discussion about fixing inconsistent "foreach"
>> statement behavior.
>> The implementation is almost done. It not only fixes inconsistencies in a
>> defined by RFC way but also improves performance in most usual cases,
>> because now foreach by value over array doesn't require array duplication.
>>
>> https://wiki.php.net/rfc/php7_foreach
>>
>> https://github.com/php/php-src/pull/1034
>>
>> I'm going to continue work on implementation improvement and may be
>> fixing related behavior of some internal functions when they used on array
>> iterated by foreach by reference (e.g. array_unshift()). However, the
>> conceptual behavior defined in RFC is not going to be changed anymore.
>>
>> Thanks. Dmitry.
>>
>
> I think the new behavior introduced by this RFC is much more consistent
> than what we have right now. Previously things depended on details of
> refcounting and hashing and had very weird interaction with current() etc.
> Now the behavior looks clear for all cases.
>
> There's just one thing I'd like to discuss: The object by-value case:
>
> Currently this is handled in much the same way as array by-reference, i.e.
> changes to the object will influence iteration. Currently we can't
> implement this any differently, however if we always use zend_array instead
> of HashTable (and fully support refcounting for this), as has been
> suggested in another thread, we could handle this case the same way as
> arrays (i.e. just add a refcount to the properties zend_array). Assuming we
> can implement it this way, I'm not totally sure which behavior makes more
> sense. On one hand it would make arrays and plain objects work the same
> way. On the other hand arrays and objects have different copying semantics
> in other places as well.
>
> Anyway, big +1 on this, thanks for implementing it.
>
> Nikita
>

Reply via email to