From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      4.3.10
PHP Bug Type:     Scripting Engine problem
Bug description:  Setting a static variable by reference makes the variable 
non-static

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 bug report at http://bugs.php.net/?id=32845&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32845&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32845&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32845&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32845&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32845&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32845&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32845&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32845&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32845&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32845&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32845&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32845&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32845&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32845&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32845&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32845&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32845&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32845&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32845&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32845&r=mysqlcfg

Reply via email to