What is the best way to share objects between other classes?
For example; a "database" object with functions that are required by the "article" and "user" objects.
I don't want to use globals (that includes singletons) or create a new instance of the object in each class, such as
function __construct() {
$this->database = new database;
$this->cache = new cache;
}
Would passing the objects in, eg.
class test{
function __construct( $obj ) {
$this->obj = $obj;
}
}
$database = new database;
$test = new test( $database );
Be the way to go?