[PHP-DEV] Request for comment From: Andi Gutmans (andi <email protected>)
Date: 08/10/00

Hi,

I just fixed a problem with foreach() which has been open a long time.
<?
        $a = array("A" => "a", "B" => "b");
        $b = $a;
        foreach($a as $ka => $va) {
                echo "$ka - $va\n";
                foreach($b as $kb => $vb) {
                        echo "$kb - $vb\n";
                }
        }
?>

What happened here is that $b was effected by the traversing of $a where it
shouldn't have. I have fixed this.
What also works is foreach(array(1,2,3 as $ka => $va)
The main problem is with weird expressions in foreach such as
foreach($a=$b) which would still have such side effect issues. I think this
code is obscure and the change of people using it is slim.
I would like to change foreach to only support:
a) foreach($var) where var could be any variable/multi-dimensionaly
variable ($a[0]).
b) foreach(array(....))

Does anyone see a problem with this? It would mean you can't put obscure
stuff into foreach().

Andi

---
Andi Gutmans <andi <email protected>>
http://www.zend.com/

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>