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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:06:17+00:00 2026-06-15T18:06:17+00:00

I want my classes to inherit a getProperties method from its superclass. class Mother

  • 0

I want my classes to inherit a getProperties method from its superclass.

class Mother {
  function getProperties(){
    return get_class_vars(get_class($this));
  } 
}

class Child extends Mother{
  private $one = 1;
  private $two = 2;
}

Problem is that if I call getProperties on Child, I get an empty result:

 $c = new Child();
 var_dump( $c->getProperties() );

returns array(0) {}

If I overwrite the getProperties method in Child with the same command, it works as expected and returns array(2) { ["one"]=> int(1) ["two"]=> int(2) }. So I figure that $this is resolved to the Mother class and not to the class that inherited the method.
How can I get Child to inherit the method in a way that it works like I need it to? Or how I change the scope of $this to work with Child instead of Mother?
Maybe I’m just missing pretty simple fact here so any help is appreciated.

  • 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-15T18:06:19+00:00Added an answer on June 15, 2026 at 6:06 pm

    The problem is that your properties are private. That makes them accessible only and exclusively to the declaring class, none other. Make them protected.

    Note though that even then there seem to be some inconsistencies among different PHP versions: http://3v4l.org/1Rm6e

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

Sidebar

Related Questions

Can I use CustomActionAttribute in classes that inherit from System.Configuration.Install.Installer? I want my class
I have two case classes that inherit from an abstract base class. I want
I want to make a class in C++, which other classes inherit from it.
I have 2 classes both inherit from the same interface. i want sometimes to
I have an assembly, and I want to list all classes that inherit from
I want to create an abstract base class for all paramter-type classes to inherit
I have 2 classes that inherit from a common base class. Each of these
I have two classes that inherit from the same base class but do not
I have multiple classes that inherit from one base class, and each class is
I have a number of LINQ classes that inherit from the same base class.

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.