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 80187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:15:47+00:00 2026-05-10T21:15:47+00:00

I have a class Page that creates an instance of DB , which is

  • 0

I have a class Page that creates an instance of DB, which is named $db.

In the __construct() of Page, I create the new $db object and I pull a bunch of config data from a file.

Now the DB class has a method _connectToDB() which (attempts) to connect to the database.

Is there a way in the DB class to call the parent class’s config array? I don’t want to make global variables if I don’t have to and I don’t want to grab the config data twice.

Pseudo code might look something like this…

$dbUsername = get_calling_class_vars(configArray['dbUserName']); 
  • 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. 2026-05-10T21:15:48+00:00Added an answer on May 10, 2026 at 9:15 pm

    I find that it’s often easier to initialise all the ‘important’ objects close to whatever variables they need to know. You could try it this way:

    /* Code to get config variables here */ $DB = new DB($config); /* You might want to delete the database password from $config here */ $Page = new Page($config, $DB); 

    Doing it this way means you can also do type-checking on the database object if you want to:

    class Page {     function __construct(array $config, DBClass $db) { } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Excel seems to open the file in exclusive mode, so… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer Microsoft don't provide a API to disable or enable today… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer flash web sites are usually applications, that are loaded once,… May 11, 2026 at 7:46 pm

Related Questions

I come from the land of Java, C#, etc. I am working on a
I have a JavaScript class that I have made and put it into its
I'm working on an ASP.NET page, using VB.NET and I have this hierarchy: Page
I was kind of scratching my head at this a week ago, and now

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.