ID:               8373
 Comment by:       giles_m_allen at yahoo dot co dot uk
 Reported By:      ocomte at guarantycity dot com
 Status:           Duplicate
 Bug Type:         Feature/Change Request
 Operating System: All
 PHP Version:      4.0.4
 New Comment:

I Agree, it would be usefull, it there any way in which you can force
it to pass by reference as it is?


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

[2001-01-23 12:09:21] [EMAIL PROTECTED]

dupe of #3074

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

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

[2000-12-22 05:47:53] ocomte at guarantycity dot com

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).

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


-- 
Edit this bug report at http://bugs.php.net/?id=8373&edit=1

Reply via email to