Objects: Cant set object variables with refrences ...

From: Date: Tue, 11 Feb 2003 09:43:44 +0000
Subject: Objects: Cant set object variables with refrences ...
Groups: php.general 
Request: Send a blank email to php-general+get-135174@lists.php.net to get a copy of this message
My problem is illistrated by the following test code: class test { var $flag = 0; function getFlag() { return $this->flag; } var $t; function Init() { $c = new test; $this->t = $c; $c->flag = 1000; } function EchoFunc() { echo("=" . $this->t->getFlag()); } } $test = new test; $test->Init(); $test->EchoFunc(); When run, the number 0 is returned. Given copying symantecs, this is what you would expect. $c is initilized with flag=0, the next line takes a copy of $c and puts it in $t, the next line sets flag=1000 on $c, but not on $t. However I would like refernce semantics and the final output of this script to be 1000. So I changed the line to "$this->t &= $c;" and suddenly I get the error: "Fatal error: Call to a member function on a non-object in /user/sh/jmb/Project/Wiki/Public_html/test.php on line 25" Anyone have any help on what is happening? Thanks, James.

« previous php.general (#135174) next »