Bug #75717 [NEW]: RecursiveArrayIterator does not traverse arrays by reference

From: Date: Thu, 21 Dec 2017 16:17:28 +0000
Subject: Bug #75717 [NEW]: RecursiveArrayIterator does not traverse arrays by reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213217@lists.php.net to get a copy of this message
From: greg at girty dot net Operating system: OSX, Debian Linux PHP version: 7.1.12 Package: SPL related Bug Type: Bug Bug description:RecursiveArrayIterator does not traverse arrays by reference Description: ------------ The expected behaviour of RecursiveArrayIterator is that only leaf nodes will be iterated, but if an array is contained by reference, it is not traversed, instead it is returned by next(). Explicit use of RecursiveIteratorIterator::LEAVES_ONLY has no affect. HHVM gives the expected result, see https://3v4l.org/up3me Test script: --------------- function flatten(array $nestedArraysAndStrings){ $flat=[]; $iter = new RecursiveIteratorIterator( new RecursiveArrayIterator($nestedArraysAndStrings)); foreach($iter as $leaf){ $flat[] = $leaf; } return join(NULL, $flat); } $noRefs = [[[['some']]],[' nested ']," items \n"]; $withRefs = []+$noRefs; $wat = $noRefs[0]; $withRefs[0] = &$wat; echo flatten($noRefs); echo flatten($withRefs); Expected result: ---------------- some nested items some nested items Actual result: -------------- some nested items Notice: Array to string conversion ... on line 8 Array nested items -- Edit bug report at https://bugs.php.net/bug.php?id=75717&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75717&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75717&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75717&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75717&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75717&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75717&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75717&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75717&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75717&r=support Expected behavior: https://bugs.php.net/fix.php?id=75717&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75717&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75717&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75717&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75717&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75717&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75717&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75717&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75717&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75717&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75717&r=mysqlcfg

« previous php.bugs (#213217) next »