|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-02-27 10:42 UTC] phil at kusala dot com
<?
function xmpdump($xValue, $sLabel="")
{
echo "$sLabel<xmp>";
var_dump($xValue);
echo "</xmp>";
}
class test
{
var $sValue;
var $Count = 0;
function getTest(&$refObj)
{
if (isset($this->sValue))
{
$refObj = &$this->sValue;
xmpdump($refObj, "Reference before being passed back");
return;
}
else
{
$refObj = "phil".$this->Count;
$this->Count++;
$this->sValue = &$refObj;
xmpdump($refObj, "Value before being passed back");
return;
}
}
}
$tst = new test();
$tst->getTest($tstObj0);
xmpdump($tstObj0, "Value after being passed back");
$tst->getTest($tstObj1);
xmpdump($tstObj1, "Refence after being passed back");
?>
The dump of $tstObj1 is NULL, despite the dump of $refObj immediately before it in the function working correctly.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 09:00:01 2025 UTC |
You can get round the above problem somewhat using: function foo (&$aVar) { $aVar['value'] =& $GLOBALS["baz"]; } foo($bar); $bar['value'] is now a reference to $GLOBALS["baz"] as you would expect.