Re: Get and object reference??

From: Date: Sat, 19 Oct 2002 03:56:03 +0000
Subject: Re: Get and object reference??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120578@lists.php.net to get a copy of this message
Hi, Saturday, October 19, 2002, 3:55:17 AM, you wrote: MH> Greetings, MH> Can anyone tell me why the following still creates a *copy* of the object?? MH> Thanks, MH> Matthew MH> <?php MH> $aFunctions = array(); MH> $oTest = new test; $oTest->>sText = "The original object."; MH> print "<pre>"; MH> foreach ( array_keys($aFunctions) as $iKey ) MH> call_user_func($aFunctions[$iKey]); $oTest->>callme(); MH> print "</pre>"; MH> class test { MH> var $sText; MH> function test() { MH> GLOBAL $aFunctions; MH> $this->sText = "A copy of the object!"; MH> /* This make a COPY of the Object, not a Reference! */ MH> $aFunctions[] = array(&$this, 'callme'); MH> } MH> function callme() { MH> print $this->sText . "\n"; MH> return; MH> } MH> } ?>> when you create the instance use this $oTest =& new test; in the constructor I do this function test() { GLOBAL $aFunctions; $this->sText = "A copy of the object!"; /* This make a COPY of the Object, not a Reference! */ $aFunctions['test'] =& $this; } -- regards, Tom

« previous php.general (#120578) next »