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

  • SEARCH
  • Home
  • 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 7930867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:33:20+00:00 2026-06-03T20:33:20+00:00

I have a base class and a a second class that’s extends the base

  • 0

I have a base class and a a second class that’s extends the base class. The problem is that I can’t access the $db object from the child class, but all normal variables.
Any idea why?

class Base_Login
{  
    protected $member_uri = 'member.php';
    protected $db;

    public function __construct($db_user, $db_password, $db_name, $db_host)
    {
        $this->db = new ezSQL_mysql($db_user, $db_password, $db_name, $db_host);
        var_dump($this->db); //Output: Object content's
    }   
}

class Facebook_Login extends Base_Login
{       
    public function __construct($app_id, $secret)
    {
        var_dump($this->db); //Output: NULL
        echo $this->member_uri //Output: member.php
    }
}

And this is how i call it:

require("includes/config.php");
$base_login = new Base_Login($db_user,$db_password,$db_name,$db_host);
$base_login->Facebook_Login = new Facebook_Login($facebook_appID,$facebook_secret);
  • 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-03T20:33:21+00:00Added an answer on June 3, 2026 at 8:33 pm

    In your parent class you have defined a constructor method. and the initialization of the database object is done in your parent class. when you define a child class and define the method with same name as parent’s what php does here is override the parent’s method will child so for example

    class Foo {
        public function a() {
            //some code execution are done here
        }
    }
    

    and now you have another class inheriting the parent class

    class Bar {
        public function a() {
    
        }
    }
    

    what php does here is ignore the parent’s method and call only the child class. workarond for this is to call your parent’s method in your child class by using parent keyword

    so in your child class

    class Bar {
        public function() {
            //call to parent method.
            parent::a();
        }
    }
    

    this will result in the parent’s as well as child method being executed. same goes for the class constructor. you need to class parent constructor method in your child class by using parent::__construct();

    hope this helps you in understanding how php handles method overriding.

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

Sidebar

Related Questions

I have a homework problem that asks: Desgin a derived class GraduateStudent from base
I have a class that extends a base class. The base class is more
I know that calling a virtual method from a base class constructor can be
I have 2 classes that inherit from a common base class. Each of these
I have a base class for all my textboxes and I want to set
Say we have a class inheriting from two base classes (multiple inheritance). Base class
I have a virtual base class and two classes that implement the various methods.
I have a User class and an Author class that extends User. I have
I have the following situation. I have a Java Class that inherits from another
I have a custom CustomMembershipUser that inherits from MembershipUser. public class ConfigMembershipUser : MembershipUser

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.