# [RFC] Fix "foreach" behavior

- Thread: https://externals.io/message/81419
- Original archive: https://news-web.php.net/php.internals/81419
- Started by Benjamin Coutu on 2015-01-30T10:41:51+00:00
- Messages: 1
- RFC: Fix "foreach" behavior (Implemented (PHP 7.0)) — https://externals.io/rfc/php7_foreach.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #81419 — Benjamin Coutu — 2015-01-30T10:41:51+00:00

URL: https://externals.io/message/81419#81419

Hi Dmitry,

Thank you for picking up on our proposal. RFC and patch look promising - awesome work!
I am looking forward to it.

Ben

========== Original ==========
From: Dmitry Stogov <dmitry@zend.com>
To: PHP Internals <internals@lists.php.net>
Date: Fri, 30 Jan 2015 08:23:19 +0100
Subject: [PHP-DEV] [RFC] Fix "foreach" behavior

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.
