Jump to content

By reference in combo with php classes


Darghon

Recommended Posts

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

  • 5 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.