Jump to content

How do include a class inside of a class


Dat

Recommended Posts

Then pass the parameter to do that to the construct or create a method

  public function setDatabase($db)
  {
    $this->_db = $db;
  }

 

Although if $this->_db is vital for the blogPost class (which I suspect it is) it belongs in the construct.

 

 

As a few hopefully constructive tips..

 

tip #1

PHP(5) supports type hinting so this works as well:

__construct(database $db)

The more strict you can get the better imo. (Als provides more useful errors when you pass in a parameter of the wrong type)

 

tip #2

You may want to stick to the general PHP (and java and probably other programming languages as well) code convention to start classnames with a capital letter, so Database and BlogPost instead of database/blogPost.

 

(this is gonna be a rather late reply.. left this open in a tab for half a day)

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.