From: chris.lucky@aon.at
Operating system: Win XP prof.
PHP version: 4.2.1
PHP Bug Type: Class/Object related
Bug description: Assignment problem
I have 2 classes linked together. In a search-method an object (or a list
of them) is created and returned.
The structure was build correct in the search-method, but when I assign
another value to the mom-object it seams that there are different
child-objects.
The following sample shows it:
####################################
#
class Mom
{
// Properties:
var $title;
var $myChild;
// Methods:
function Mom ($title = "")
{
$this->title = $title;
}
function init (&$child)
{
$this->myChild = &$child;
}
function search ()
{
$mom = new Mom ("test10");
$child = new Child ();
$mom->init (&$child);
$child->init (&$mom);
return $mom;
}
} # end class Mom
####################################
#
class Child
{
// Properties:
var $myMom;
// Methods:
function Child ()
{
}
function init (&$mom)
{
$this->myMom = &$mom;
}
} # end class Child
####################################
#
# test code:
$m = new Mom ();
$mom = $m->search ();
$t0 = $mom->title;
$t1 = $mom->myChild->myMom->title;
echo "$t0 = $t1<br>\n"; # correct values
$mom->title = "test1";
$t0 = $mom->title;
$t1 = $mom->myChild->myMom->title;
echo "$t0 != $t1<br>\n"; # why are t0 and t1 different?
Is there a bug in my code or in php?
Thanks,
Chris
--
Edit bug report at http://bugs.php.net/?id=18866&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18866&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18866&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18866&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18866&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18866&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18866&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18866&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18866&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18866&r=globals