Bug #62110 [Opn->Nab]: Foreach creates a copy of the array passed by value in function
| From: | johannes@php.net | Date: | Thu, 24 May 2012 10:15:42 +0000 |
| Subject: | Bug #62110 [Opn->Nab]: Foreach creates a copy of the array passed by value in function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-170763@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62110&edit=1
ID: 62110
Updated by: johannes@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
+Status: Not a bug
Type: Bug
Package: Performance problem
Operating System: Arch Linux
PHP Version: 5.4.3
Block user comment: N
Private report: N
New Comment:
As said above.
Previous Comments:
------------------------------------------------------------------------
[2012-05-24 00:14:35] a dot protaskin at gmail dot com
Thanks for your answers, nikic. I read your answer in the neighbouring entry and your articles too.
I understood this behaviour, this is not the bug.
Sorry for my bad english.
------------------------------------------------------------------------
[2012-05-23 21:59:30] nikic@php.net
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.
------------------------------------------------------------------------
[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