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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:46:25+00:00 2026-05-31T07:46:25+00:00

I have 2 classes that inherits from a father class. The father class has

  • 0

I have 2 classes that inherits from a father class. The “father” class has a protected variable that is being populated in both of the child classes, each of the classes populates it with different information for a database.

My problem is that when I create instances of both classes, the second instance changes the the values from the first instance.

Here is the code:

class User
{
    //array with the MySQL Server details//
    private $serverInfoArray = array("host" => HOST, "user" => USER, "pass" => PASS);

    protected $data; //This will be populated with data in both of the "child" classes.

    //some database connection functions....//

    public function setData(){} //implemented on "child" classess

    public function getData(){} //implemented on "child" classess

}

and here are one the child classes:

class Producer extends User
{

    function __construct($id)
    {
        $this->setData($id);  
    }

    public function setData($id)
    {
        global $serverInfoArray, $data;
        $connectionFB;

        $query = "MY FIRST QUERY"; //IN THE SECOND CHILD CLASS 
                                   //IT HAS DIFFERENT QUERY

        $result = mysql_query($query, $connectionFB);

        $i=0;

        while($row = mysql_fetch_array($result))
        {
            $data[$i] = $row;
            $i++;
        }     
    }

    public function getData()
    {
        global $data;
        return $data;    
    } 
}

The second class has the same structure but is different in its name and the query being executed. Its declaration is class Account extends User

When I create 2 instances:

$producer = new Producer($_SESSION['PRODUCER_ID']); 
$account = new Account($_SESSION['ACCOUNT_ID']);

and do this:

  var_dump($producer->getData());

I get the values of $data that was populated by the second query. If I wont create the account instance it will return the values of populated in the first class.

Why does the account instance changes the values of $data from the producer class instance, how can I separate them ?

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-05-31T07:46:27+00:00Added an answer on May 31, 2026 at 7:46 am
    1. Remove the following line:

      global $serverInfoArray, $data;
      
    2. Use $this->serverInfoArray & $this->data to access class variables.

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

Sidebar

Related Questions

Newbie Python question. I have a class that inherits from several classes, and some
I have a bas class called Media with two classes that inherit from it,
In Django, when you have a parent class and multiple child classes that inherit
I have a class that inherits from ObservableCollection<T> to re-use the INotifyCollection functionality, but
I have a class BatchItem that inherits QObject , plus several classes that inherit
I have a CsvWriter class that inherits from a Writer class. The Writer class
I have a class that inherits from TreeNode, called ExtendedTreeNode. To add an object
I've got two classes: a template class, and a regular class that inherits from
I have a parent class in Android that inherits from Activity and all my
I'm creating a class that inherits from a parent class with protected instantiation. The

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.