From:             brunswim at seas dot upenn dot edu
Operating system: Debian Linux 2.4.18
PHP version:      4.3.1
PHP Bug Type:     Scripting Engine problem
Bug description:  returning reference to uninitialized variable

f() returns a reference to an uninitialized variable $a. In subsequent
calls, this appears to corrupt the local variable $x. The following script
demonstrates the problem.

<?
function &f() {
        $x = "foo";
        var_dump($x);
        print "<br>\n$x<br>\n";
        return($a);
}
for ($i = 0; $i < 8; $i++) {
        $h =& f();
}
?>

On the third call to f(), $x prints fine but is reported to be NULL by
var_dump().  Operations on $x will subsequently cause unexpected
behavior.

We can change the behavior of $x by adding the line:
$y = "bar";
after the line:
$x = "foo";

If we do this, printing $x returns "bar" but var_dump() still returns
NULL.
-- 
Edit bug report at http://bugs.php.net/?id=22836&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=22836&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=22836&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=22836&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=22836&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=22836&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=22836&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=22836&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=22836&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=22836&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=22836&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22836&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=22836&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=22836&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=22836&r=gnused

Reply via email to