Darghon Posted May 23, 2008 Share Posted May 23, 2008 I sketch of what I'm trying to do I made a database class, consisting of functions to execute queries, make prepared statements, logging, the works now, the application that I'm writing runs on several other classes that require database access. so I pass the database object as a parameter, and it all works like a charm now I want to be able to log all uses of the database, so in order to do this, I want to pass the database object as a by reference object to the other classes now I'm not quite sure how to accomplish this, I know that I can pass the variable with &$db (for instance), but, in the class I'm saving the parameter as : $this->db = $db; Correct me if I'm wrong but doesn't that make me lose the reference to the original DB object, and just create a new one in that class? how can I make sure I'm always working with the same DB object, without working with global stuff and so on... or is my way the correct one? thx in advance Link to comment https://forums.phpfreaks.com/topic/106923-by-reference-in-combo-with-php-classes/ Share on other sites More sharing options...
azuka Posted November 23, 2008 Share Posted November 23, 2008 If you're using PHP 5 you need not worry about that. All objects are passed by reference and you don't get a copy unless you specifically clone the object. Link to comment https://forums.phpfreaks.com/topic/106923-by-reference-in-combo-with-php-classes/#findComment-696836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.