[PHP] Re: referencing a class

2004-09-08 Thread Matthew Weier O'Phinney
* Jed R. Brubaker <[EMAIL PROTECTED]>:
> Quick question here. Has anyone run into trouble with a variable reference 
> to a class object?
>
> Here is the code:
> $_SESSION['database'] = new Database;
> $this->db = &$_SESSION['database'];
>
> Everything goes screwy after a call like this.

You don't say what version of PHP you're using, but I'm guessing 4 (as
PHP5 passes all objects by reference).

They way I've handled the above is as follows:

$_SESSION['database'] =& new Database;
$this->db =& $_SESSION['database'];

You need to get a reference to the object from the very beginning; I've
tried a variety of ways, and this is the only one that works
consistently.

-- 
Matthew Weier O'Phinney   | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: referencing a class

2004-09-08 Thread Torsten Roehr
"Jed R. Brubaker" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Quick question here. Has anyone run into trouble with a variable reference
> to a class object?
>
> Here is the code:
> $_SESSION['database'] = new Database;
> $this->db = &$_SESSION['database'];
>
> Everything goes screwy after a call like this.
>
> Thanks in advance!

What do you mean with "screwy"? Change $_SESSION['database'] after your
second line and print out $this->db to see if that was changed too.

By the way, you mean "referencing an object" (not a class).

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: referencing a class

2004-09-08 Thread Torsten Roehr
"Jed R. Brubaker" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Quick question here. Has anyone run into trouble with a variable reference
> to a class object?
>
> Here is the code:
> $_SESSION['database'] = new Database;
> $this->db = &$_SESSION['database'];
>
> Everything goes screwy after a call like this.
>
> Thanks in advance!

What do you mean with "screwy"? Change $_SESSION['database'] after your
second line and print out $this->db to see if that was changed too.

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php