What is the best way to share objects between other classes?
For instance; A database object with the functions required by the article and user objects.
I do not want to use global variables (including singlets) or create a new instance of an object in each class, for example
function __construct() { $this->database = new database; $this->cache = new cache; }
Would miss objects, for example.
class test{ function __construct( $obj ) { $this->obj = $obj; } } $database = new database; $test = new test( $database );
Will you go?
INTY
source share