returning reference to uninitialized variable
| Bug #22836 | returning reference to uninitialized variable | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2003-03-23 22:53 UTC | Modified: | 2003-07-30 11:53 UTC |
|
||||||||||
| From: | brunswim at seas dot upenn dot edu | Assigned: | ||||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 4.3.2-RC | OS: | Debian Linux 2.4.18 | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2003-03-23 22:53 UTC] brunswim at seas dot upenn dot edu
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.
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2003-03-24 01:45 UTC] brunswim at seas dot upenn dot edu
[2003-03-24 03:41 UTC] sniper@php.net
[2003-03-24 04:29 UTC] moriyoshi@php.net
[2003-03-24 11:39 UTC] brunswim at seas dot upenn dot edu
[2003-03-25 17:41 UTC] jseverson at myersinternet dot com
[2003-07-29 12:57 UTC] iliaa@php.net
[2003-07-30 11:53 UTC] sniper@php.net