RE: object passing by reference
| From: | Hoffman, Geoffrey | Date: | Wed, 27 Nov 2002 16:19:47 +0000 |
| Subject: | RE: object passing by reference | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-126302@lists.php.net to get a copy of this message | ||
Tom, you rule. It works.
I figured out my problem with my other script too.
I had written get and set accessor methods in my class. I discovered that
attempting to pass the reference to the set method in the class constructor
DOES NOT work, while setting it directly in the class constructor DOES work!
// DOES NOT WORK
class parentClass {
var $a;
function parentClass(&$_a){
$this->setA(&$_a);
}
function setA(&$_a){
$this->a =& $_a;
}
}
// DOES WORK
class parentClass {
var $a;
function parentClass(&$xa){
$this->a =& $xa;
}
// doesn't work from constructor
function setA(&$_a){
$this->a =& $_a;
}
}
Hope this helps someone else out there.
-Geoff
-----Original Message-----
From: Tom Rogers [mailto:trogers@kwikin.com]
Sent: Wednesday, November 27, 2002 7:56 AM
Cc: php-general@lists.php.net
//[snip]
function parentClass($_x, &$_child) {
//<<<<<<<<<<<<<
//[snip]
$this->child =& $_child; //<<<<<<<<<<
//[snip]