Doc #76387 [NEW]: Different behavior between Array and ArrayIterator in foreach loop...

From: Date: Tue, 29 May 2018 07:55:17 +0000
Subject: Doc #76387 [NEW]: Different behavior between Array and ArrayIterator in foreach loop...
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15722@lists.php.net to get a copy of this message
From:             Evgeny dot Mazanik at gmail dot com
Operating system: Windows 10
PHP version:      7.2.6
Package:          SPL related
Bug Type:         Documentation Problem
Bug description:Different behavior between Array and ArrayIterator in foreach loop...

Description:
------------
---
From manual page: http://www.php.net/arrayiterator.offsetunset
---

Different behavior when using Array and ArrayIterator in a foreach loop
when using unset () for an associative array.

1. When using an Array in a loop and removing an element in the body of
the loop, the loop is executed across all elements of the array.

2. When using ArrayIterator in a loop and deleting an element in the
body of the loop, the loop is NOT performed on all elements of the
array.

PS:
A similar problem:
https://bugs.php.net/bug.php?id=75173&edit=2


Test script:
---------------
http://sandbox.onlinephpfunctions.com/code/ff65bf3858b153780b588476ebaa77b0aba7b4db

Actual also for PHP 7.2.4, 7.2.6

Expected result:
----------------
Probably:

Via array:
item1
item2
item3
Via ArrayIterator:
item1
item2
item3


Actual result:
--------------
Via array:
item1
item2
item3
Via ArrayIterator:
item1
item3


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



Thread (2 messages)

« previous php.doc.bugs (#15722) next »