Object problem
| From: | Mathieu Dumoulin | Date: | Tue, 23 Jul 2002 18:20:31 +0000 |
| Subject: | Object problem | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-5621@lists.php.net to get a copy of this message | ||
I'm trying to pass an object i created from outside another object...
ex:
i created this object called mysql_connection (which keeps a connection to
my database). If i pass it to the constructor of my new class:
collection_players, it will create a copy of this class.
I tried several ways of passing a reference of the object in the constructor
but they all failed, i found a way to do it but you have to set the
reference from outside the construtor like this:
$my_collection_players->mysql_server = &$mysql_server;
This works fine, but if i want other users to use this class i don't want
them to HAVE to add another line to their script to do this kind of
assignation. Also it makes my class prone to errors. If the user doesn't put
the mysql_connection it will crash.
Also, i just noticed that the current state of my application is dangerous
because i create a mysql_connection and close it but the copy of this
connection when i pass it in all my constructors is NEVER closed...not good
for the server.
please help
InsaneCoder
(now i am insane)