[PHP-BUG] Bug #62110 [NEW]: Foreach creates a copy of the array passed by value in function

2012-05-22 Thread a dot protaskin at gmail dot com
From: 
Operating system: Arch Linux
PHP version:  5.4.3
Package:  Performance problem
Bug Type: Bug
Bug description:Foreach creates a copy of the array passed by value in function

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 bug report at https://bugs.php.net/bug.php?id=62110&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62110&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62110&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=62110&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62110&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62110&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62110&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=62110&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=62110&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=62110&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=62110&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=62110&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=62110&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=62110&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62110&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=62110&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=62110&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=62110&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=62110&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=62110&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=62110&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=62110&r=mysqlcfg



[PHP-BUG] Bug #62123 [NEW]: Foreach changes the internal pointer of the array strangely

2012-05-23 Thread a dot protaskin at gmail dot com
From: 
Operating system: Linux
PHP version:  5.4.3
Package:  Arrays related
Bug Type: Bug
Bug description:Foreach changes the internal pointer of the array strangely

Description:

Traversing the array changes once the internal pointer by 1.
Traversing the array by link changes the internal pointer just as with
each().

Test script:
---
https://bugs.php.net/bug.php?id=62123&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62123&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62123&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=62123&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62123&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62123&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62123&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=62123&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=62123&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=62123&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=62123&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=62123&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=62123&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=62123&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62123&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=62123&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=62123&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=62123&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=62123&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=62123&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=62123&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=62123&r=mysqlcfg



Bug #62123 [Com]: Foreach changes the internal pointer of the array strangely

2012-05-23 Thread a dot protaskin at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=62123&edit=1

 ID: 62123
 Comment by:     a dot protaskin at gmail dot com
 Reported by:    a dot protaskin at gmail dot com
 Summary:Foreach changes the internal pointer of the array
 strangely
 Status: Open
 Type:   Bug
 Package:Arrays related
 Operating System:   Linux
 PHP Version:5.4.3
 Block user comment: N
 Private report: N

 New Comment:

Thanks for your answer, nikic. I understood this behaviour, this is not the bug.


Previous Comments:

[2012-05-23 21:54:57] ni...@php.net

See http://stackoverflow.com/a/8263425/385378 for an explanation.


[2012-05-23 13:23:38] a dot protaskin at gmail dot com

Description:

Traversing the array changes once the internal pointer by 1.
Traversing the array by link changes the internal pointer just as with each().

Test script:
---
https://bugs.php.net/bug.php?id=62123&edit=1


Bug #62110 [Com]: Foreach creates a copy of the array passed by value in function

2012-05-23 Thread a dot protaskin at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=62110&edit=1

 ID: 62110
 Comment by:     a dot protaskin at gmail dot com
 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:

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.


Previous Comments:

[2012-05-23 21:59:30] ni...@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