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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:22:22+00:00 2026-05-28T16:22:22+00:00

I am trying to access the variables from the parent class as shown below:

  • 0

I am trying to access the variables from the parent class as shown below:

 //PARENT CLASS
class InfoString{
    private $username = "JOE";

    public function _construct(){}

    protected function get_username(){
        return $this->username;
    }         
}


class Service extends InfoString{
    //this class should now inherit the variables in InfoString, right??
    public function _construct(){}

    public function hello_username(){
        echo "HELLO! ". parent::get_username(); 
    }
}

and I call the class like so:

$a = new Service();
$a->hello_username(); //prints nothing, instead of the username

Instead of getting “HELLO! JOE”, I get an empty string. What am I doing wrong here?

Also, suppose the class ‘InfoString’ will contain configuration parameters – is it a good idea to extend this class, or what would be the proper implementation to get the config variables from, say class ‘InfoString’ into another class???

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-28T16:22:24+00:00Added an answer on May 28, 2026 at 4:22 pm

    You’re just extending InfoString, so you can just use $this->get_username(); and it will work fine. :: is for calling static methods.

    Also, you’d get an error if you’d increase your error level. Call error_reporting(E_ALL); this will give you clues to solve similar issues in the future.

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

Sidebar

Related Questions

I'm trying to access protected variables in a second-child class extended from its parent,
Im trying to access some variables from the parent in a child mc. Parent
I am trying to access STATIC Variables from one java class to another but
I'm trying to access some variables from my parent in my child MC. Parent
I am trying to access member variables of a class without using object. please
I'm trying to access the member variables of a prototype class in JavaScript in
I have a nested function where I am trying to access variables assigned in
When trying to access __variables from a class, the parser assumes the 2 underscores
I'm trying to access instance variables from within a nested object ('action'). The only
I am trying to access a variable defined in parent file from inside 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.