Jump to content

Including Objects within another object


enerjiza

Recommended Posts

I'm still relatively new to OOP so I'm not sure if I'm doing this effeciently.

 

Below are 2 examples of how I'm handling classes:

class authors {
private $db;
private $articles;

public function __construct($db) {
$this->db = $db;
$this->articles = new Articles();
}

}

 

Is there any other way I can call methods from the articles class without instantiating the articles class in the Authors class?

 

I'm using PDO and passing the connection to the Authors class in the construct, is this the right way or is there a better way of handling this?

 

Any input would be great.

 

Link to comment
https://forums.phpfreaks.com/topic/72839-including-objects-within-another-object/
Share on other sites

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.