Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:30:37+00:00 2026-06-05T15:30:37+00:00

I am doing this currently, class Page { // variable to hold DBC class

  • 0

I am doing this currently,

class Page {
    // variable to hold DBC class
    public $dbc;
    /*
        __CONSTRUCT
        Called when class is initiated and sets the dbc variable to hold the DBC class.
    */
    public function __construct() {
        // set the dbc variable to hold the DBC class
        $this -> dbc = new DBC();
    }
    /*
        CREATE PAGE
        Create a page with the option to pass data into it.
    */
    public function create($title, $class, $data = false) {
        // start buffer
        ob_start('gz_handler');
        // content
        content($this -> dbc, $data);
        // end buffer and flush
        ob_end_flush();
    }

}

I have simplified the example, but basically I need to pass the object DBC to a function inside the method create?

Is this considered bad practice as I was using extends before but realised there was no way to extract the extended class to a variable?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:30:39+00:00Added an answer on June 5, 2026 at 3:30 pm

    You’re very close to the dependency injection design pattern.

    You just have to change your constructor to accept the object as a parameter, like so:

    public function __construct( $dbc) {
        // set the dbc variable to hold the DBC class
        $this -> dbc = $dbc;
    }
    

    Then instantiate your class with the database connection, like so:

    $dbc = new DBC();
    $page = new Page( $dbc);
    

    This has a variety of benefits, ranging from easier to test, to making a single connection to the database. Imagine you need five Page objects – Now you pass them all the same database connection so they do not need to individually create one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm doing it in this fashion: class Spam(object): decorated = None @classmethod def
I am currently doing this, but I am doing something wrong :): <Style TargetType={x:Type
I'm currently doing this query to find the guy who makes the most calls:
Buried in mySQL syntax and query structure problems once more. I'm currently doing this
Currently I am doing this: I have text that looks like: Hello ${user.name}, this
currently I am doing this... object s = new object(); s = mydatarow[mycolumn]; What
I'm currently learning the adf framework, and while doing this I found myself in
Here is what I have currently, I'm doing this: current_account.send(object).search(params[:search]).user_id_equals_any(users).visibility_is_any(visibilities) but thats not very
Hi i am currently taking a Matrix, P, and doing this P500 = MatrixPower[P,
My site currently handles URL's like this... /?p=home /?p=profile&userid=1 /?p=users.online /?p=users.online&page=23 /?p=mail.inbox /?p=mail.inbox&page=12 ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.