[PHP-DEV] PHP 4.0 Bug #9481 Updated: Passing out class property by reference problem

2001-03-08 Thread stas

ID: 9481
Updated by: stas
Reported By: [EMAIL PROTECTED]
Old-Status: Open
Status: Closed
Bug Type: Scripting Engine problem
Assigned To: 
Comments:

This is not a bug. Please read the "References explained"
part in the manual. When you have $a = $b and you do $a =
$c, you don't make a and b be references to c, you make only
$a bound to $c and unbound from $b. So when you did $refObj
= $this-sValue
 $refObj stopped being reference to call parameter and
became reference to $this-sValue. There's no real way to
make "other" referenced value to be rebound to some new value.

Previous Comments:
---

[2001-02-27 10:42:34] [EMAIL PROTECTED]
?
function xmpdump($xValue, $sLabel="")
{
echo "$sLabelxmp";
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.


---



ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=9481edit=2


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] PHP 4.0 Bug #9481 Updated: Passing out class property by reference problem

2001-03-08 Thread phil

ID: 9481
User Update by: [EMAIL PROTECTED]
Status: Closed
Bug Type: Scripting Engine problem
Description: Passing out class property by reference problem

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.


Previous Comments:
---

[2001-03-08 06:58:36] [EMAIL PROTECTED]
This is not a bug. Please read the "References explained"
part in the manual. When you have $a = $b and you do $a =
$c, you don't make a and b be references to c, you make only
$a bound to $c and unbound from $b. So when you did $refObj
= $this-sValue
 $refObj stopped being reference to call parameter and
became reference to $this-sValue. There's no real way to
make "other" referenced value to be rebound to some new value.

---

[2001-02-27 10:42:34] [EMAIL PROTECTED]
?
function xmpdump($xValue, $sLabel="")
{
echo "$sLabelxmp";
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.


---


Full Bug description available at: http://bugs.php.net/?id=9481


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]