Edit report at https://bugs.php.net/bug.php?id=62110&edit=1

 ID:                 62110
 Comment by:         ni...@php.net
 Reported by:        a dot protaskin at gmail dot com
 Summary:            Foreach creates a copy of the array passed by value
                     in function
 Status:             Open
 Type:               Bug
 Package:            Performance problem
 Operating System:   Arch Linux
 PHP Version:        5.4.3
 Block user comment: N
 Private report:     N

 New Comment:

The foreach loop changes the internal array pointer. If the array zval wouldn't 
be separated the loop thus would thus affect he array which was passed by 
value, which is obviously not acceptable.


Previous Comments:
------------------------------------------------------------------------
[2012-05-22 19:56:06] a dot protaskin at gmail dot com

Description:
------------
I also tried to execute this code on PHP 5.3.13 and PHP 5.2.17 with same result.

All options are default.

Test script:
---------------
http://pastebin.com/caczCxuD

Expected result:
----------------
Start: 786432
Inner by_reference: 786432
Inner foreach: 786432
After by_reference: 786432
Inner by_value: 786432
Inner foreach: 786432
After by_value: 786432

Actual result:
--------------
Start: 786432
Inner by_reference: 786432
Inner foreach: 786432
After by_reference: 786432
Inner by_value: 786432
Inner foreach: 1310720
After by_value: 104857


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62110&edit=1

Reply via email to