a simplified example......
| From: | Lukasz Michalski | Date: | Thu, 06 Jul 2000 09:28:05 +0000 |
| Subject: | a simplified example...... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5191@lists.php.net to get a copy of this message | ||
In article <396322A3.70CBF30A@clan.pl>, zork@clan.pl (Lukasz Michalski)
wrote:
> > exchangedays() operates on $caday so It shouldn't change any data in
> > copy of that object $bday.
> Unless $caday points to $bday internally, and you alter it through
that?...
Hi,
I managed simplify and shrink my code to that below. When you execute it
you get this results:
3n
3t
6 n
6 t
3n
3t
It looks like two objects, $newday and $t share one array ($visits) and
when i modify $t by calling its method $newday gets modified too. It
happends only to this array If you play with 'checked' properity of any
instances you'll see that everything is fine.
Only "workaround" that comes to my mind is not to use "=" but manually
create and copy all properites of object that I want to reproduce.
I've already submitted it as a bug
greetings.
Łukasz Michalski
zork@clan.pl
<?
class Cvisit {
var $status;
};
class Cdaydesc {
var $visits = array();
var $checked = 0;
function setvisittime() {
for($i = 0; $i < count($this -> visits); $i++) {
if ($this -> visits[$i] -> status == 6) {
$this -> visits[$i] -> status = 3;
} else
if ($this -> visits[$i] -> status == 3) {
$this -> visits[$i] -> status = 6;
};
};
}
function addvisit($visit) {
$this -> visits[] = $visit;
}
};
$visit = new Cvisit();
$visit -> status = 6;
$newday = new Cdaydesc();
$newday -> addvisit($visit);
$t = $newday;
$t -> checked = 1;
$t -> visits[0] -> status = 3;
echo $newday -> visits[0] -> status."n<br>";
echo $t -> visits[0] -> status."t<br>";
$t -> setvisittime();
echo $newday -> visits[0] -> status." n<br>";
echo $t -> visits[0] -> status." t<br>";
$t -> setvisittime();
echo $newday -> visits[0] -> status."n<br>";
echo $t -> visits[0] -> status."t<br>";
?>