php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6750 passing undefined variables by reference mangles function parameters
Submitted: 2000-09-14 02:07 UTC Modified: 2000-12-16 13:49 UTC
From: dshadow at zort dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dshadow at zort dot net
New email:
PHP Version: OS:

 

 [2000-09-14 02:07 UTC] dshadow at zort dot net
Passing an undefined variable or function result to a function expecting said parameter by reference mangles the function parameters.

The following script results in this output:

	SomeFunc(2, 2, 2)  //this is really bad
	SomeFunc(1, 2, 1)  //This is correct
	SomeFunc(1, 2, 2)  //This isn't correct, but it's not good either

This bug is in PHP 4.0.2 and the 4.0.3 CVS. The earliest version I know of with the problem is a 4.0.2 CVS with a build date of Jul 21, so the problem has existed since at least then.

---

function returnUndef() {
	return $foo;
}

function returnDef() {
	return 1;
}

function SomeFunc($a, $b, &$c) {
	echo("SomeFunc($a, $b, $c)\n");
}

SomeFunc(1, 2, returnUndef());
SomeFunc(1, 2, returnDef());
SomeFunc(1, 2, $bar);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-14 03:09 UTC] waldschrott@php.net
argh, this is really bad, what seems to happen is (verified with modified tests):

if a non-existent variable (NULL works) is passed to the referenced parameter, *all* other parameters are overwritten with the value of the precessing variable the referenced one too, what explains the current buggy behaviour at the third function call
 [2000-12-16 13:49 UTC] waldschrott@php.net
this if fixed now, it was related to some undefined
behaviour using references and function calls
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 28 06:00:01 2026 UTC