#50532 [NEW]: Lazy-evaluated multiple-array foreach
From: jsimlo at yahoo dot com
Operating system: irrelevant
PHP version: 5.3.1
PHP Bug Type: Feature/Change Request
Bug description: Lazy-evaluated multiple-array foreach
Description:
------------
I would like to suggest an extended foreach syntax like this:
<?php
foreach ($a, $b, $c as $k => $i)
echo $i;
?>
Which would result in the same execution as current:
<?php
foreach (array ($a, $b, $c) as $x)
foreach ($x as $k => $i);
echo $i;
?>
The reason for requesting this is (simplicity and) possibility of
lazy-evaluation of the source arrays. The source arrays can be expressions
that take time to compute; or consume large memory each while they exist;
and the body of the foreach can break the foreach cycle, rendering a
lazy-evaluation quite worth the trouble. Example:
<?php
// several not-so-easy-to-compute arrays
foreach (
$item1->GetChilds(),
$item2->GetChilds(),
$item3->GetParent()->GetChilds(),
$item3->GetComputeSomethingDifficultChilds()
as $child
)
// searching for a child with a special name
if ($child->GetName() == 'something') break;
// now we got a child of such name (or the last cycled child)
print_r ($child);
Reproduce code:
---------------
---
From manual page: control-structures.foreach
---
--
Edit bug report at http://bugs.php.net/?id=50532&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50532&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50532&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50532&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50532&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50532&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50532&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50532&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50532&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50532&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50532&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50532&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50532&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50532&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50532&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50532&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50532&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50532&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50532&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50532&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50532&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50532&r=mysqlcfg
Thread (2 messages)
- jsimlo at yahoo dot com