ID:               32845
 User updated by:  [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      4.3.10, 5.0.4
 New Comment:

Sorry about that, I didn't see that part of the manual. Still, this
doesn't seem like good behavior...


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

[2005-04-27 12:48:27] [EMAIL PROTECTED]

RTFM:   
  
  http://www.php.net/manual/en/language.variables.scope.php

And the part with title:

  "References with global and static variables"



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

[2005-04-26 19:40:08] [EMAIL PROTECTED]

Description:
------------
When setting a static variable by reference (as one would want to do in
PHP4 since the object model uses copies instead of references) the
static variable becomes non-static and is lost when the function ends.
I assume this could be fixed by making the reference itself static
instead of the variable.

This can also be "fixed" by using a container as the static variable
(an array or object) and setting the var by ref within the
array/object.

$v[0] =& $var;
or
$v->v =& $var;

I also tested this in PHP 5.0.4 and the same thing happens. I realize
that PHP5 uses refs instead of copies by default.

Reproduce code:
---------------
function a() {
    static $v;
    $a = 0;
    if (!isset($v)) {
        $v =& $a;
        echo 'setting v<br/> ';
    }
}
a();
a();
function b() {
    static $w;
    $a = 0;
    if (!isset($w)) {
        $w = $a;
        echo 'setting w<br/> ';
    }
}
b();
b();

Expected result:
----------------
setting v
setting w

Actual result:
--------------
setting v
setting v
setting w


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


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

Reply via email to