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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:57:59+00:00 2026-06-11T04:57:59+00:00

Can anyone explain why is the get_class function returning different values below? Specifically, what

  • 0

Can anyone explain why is the get_class function returning different values below? Specifically, what is it supposed to do when it is called in a base class and when it is called in a derived class?

abstract class bar {
    public function __construct()
    {
        var_dump(get_class($this)); //prints 'foo'
        var_dump(get_class()); // prints 'bar'
    }
}

class foo extends bar {
}

new foo;
  • 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-11T04:58:01+00:00Added an answer on June 11, 2026 at 4:58 am

    It seems quite well explained in the documentation, but here it is:

    get_class($instance) returns the class of the $instance instance, regardless of where you’re calling it; get_class($this) does behave the same way, returning the class of $this.

    get_class() returns the class where the method calling it is defined, thus it returns bar in your example, as that is where __construct() is defined (even though you’re calling it through inheritance).

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

Sidebar

Related Questions

Can anyone explain the following PHP Code ? function get_param($param_name, $param_type = 0) {
can anyone explain me what happen here?? i have this html code: <div class=calculadora>
Can anyone explain the below code can any one give some real time explanation
I am having problems with the below code, can anyone explain why the method
Can anyone explain how I can successfully get my processes communicating? I find the
Can anyone explain when using an anonymously hosted dynamic method why I get an
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone explain why here a = [] ? 1 : 2 a will
Can anyone explain me how to overpass these problems? Description Resource Path Location Type
Can anyone explain to me why there is a dramatic difference in performance between

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.