ID: 8373
Updated by: cynic
Reported By: [EMAIL PROTECTED]
Old-Status: Open
Status: Duplicate
Bug Type: Feature/Change Request
Assigned To: 
Comments:

dupe of #3074

btw, +1 for foreach( $a as &$v ) :)

Previous Comments:
---------------------------------------------------------------------------

[2000-12-22 05:47:53] [EMAIL PROTECTED]
It would be very useful (at least for me) if the fonction foreach support references. 
For example the code :
<?
class Foo
{       var $Ok=false;
        function EchoOk()
        {       if ($this->Ok)
                        echo "OK<br>n";
                else
                        echo "KO<br>n";
        }
}

$Bar=array();
$Bar[]=new Foo;
foreach($Bar as $v)
        $v->SetOk();
foreach($Bar as $v)
        $v->EchoOk();
?>
will produce the output :
KO<br>

I know I can replace the first loop by :
foreach($Bar as $k => $v)
        $Bar[$k]->SetOk();
but, in this case, the $v is useless.

I suggest to accept the notation
foreach($Arr as &$RefVal)
and
foreach($Arr as $Key => &$RefVal)
in a future PHP release to make $RefVal a reference on each $Arr elements (and not a 
copy).

---------------------------------------------------------------------------


Full Bug description available at: http://bugs.php.net/?id=8373


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to