#18866 [Opn->Bgs]: Assignment problem
| From: | rodif_bl@php.net | Date: | Mon, 12 Aug 2002 13:29:06 +0000 |
| Subject: | #18866 [Opn->Bgs]: Assignment problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16540@lists.php.net to get a copy of this message | ||
ID: 18866
Updated by: rodif_bl@php.net
Reported By: chris.lucky@aon.at
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Win XP prof.
PHP Version: 4.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You need to add a few more refrences.
$m = $m->search(); // this does a copy too
$m = &$m->search(); // this will make it work
you will need to change
function search()
to
function &search()
It works for me after these changes
Previous Comments:
------------------------------------------------------------------------
[2002-08-12 05:27:33] chris.lucky@aon.at
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 this bug report at http://bugs.php.net/?id=18866&edit=1