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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:26:43+00:00 2026-05-31T21:26:43+00:00

I have a Handler class that looks like this: class Handler{ public $group; public

  • 0

I have a Handler class that looks like this:

class Handler{
    public $group;

    public function __construct(){
        $this->group = $this->database->mysql_fetch_data("blabla query");
        //if i print_r($this->group) here it gives proper result

        new ChildClass();
    }

    public function userGroup(){
        print_r($this->group); //this is empty
                    return $this->group;
    }
}

class ChildClass extends Handler{

    public function __construct(){
        $this->userGroup();
        //i tried this too
        parent::userGroup();
        //userGroup from parent always returns empty
    }

}

Workflow:

  • Handler is called from my index.php and the __construct is called

  • Handler needs to create $group

  • Handler creates child class

  • Child class calls Handler function

  • When I try to return $group in the function It tries to get $this->group from Child instead of Handler

Whenever I try to ask the parent something I can only access the parent function then inside the function the parent class can’t find any of it’s own variables

EDIT:

I figured using ‘extends’ would be useful in calling parent functions but it seems just passing $this on to the child will be easier.

  • 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-31T21:26:45+00:00Added an answer on May 31, 2026 at 9:26 pm

    You never called the parent constructor, so the group object is never initialized. You will want to do something like this.

    class Handler{
        public $group;
    
        public function __construct(){
            $this->group = $this->database->mysql_fetch_data("blabla query");
            //if i print_r($this->group) here it gives proper result
    
            new ChildClass();
        }
    
        public function userGroup(){
            print_r($this->group); //this is empty
                        return $this->group;
        }
    }
    
    class ChildClass extends Handler{
    
        public function __construct(){
            parent::__construct();
            $this->userGroup();
        }
    
    }
    

    If you had not overwritten the __construct method in your extended class, then the parent __construct would have automatically been called, but since you overwrote it in the extended class, you must tell it to call the parent’s __construct in your extended class’ __construct.

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

Sidebar

Related Questions

Let's say I have a manager that looks something like this: public class CustomerManager
Okay, so say I have a class that looks like this : public class
I've implemented a class that looks like this interface: [ImmutableObject(true)] public interface ICustomEvent {
I have a basic Spring MVC controller that looks like this: @Controller public void
I have a simple Controller that looks like this:- @Controller @RequestMapping(value = /groups) public
I have a control that looks along the lines of this: public class MyControl
I have a file that looks like this: namespace myName { typedef HRESULT (*PFN_HANDLE)(myName::myStruct);
My WCF Service in C# looks like this. [ServiceContract] public class MySecretService { [OperationContract]
I created a very simple event publisher and it looks like this. public class
I have a C++ RAII class for managing Win32 HANDLEs using boost::shared_ptr<> that looks

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.