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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:44:07+00:00 2026-06-13T04:44:07+00:00

I don’t get how this late static binding works. abstract class A{ final public

  • 0

I don’t get how this late static binding works.

abstract class A{

  final public static function doprint(){
    print get_called_class() . '<br>';
  }


  public static function wrapper(){
    self::doprint();
    static::doprint();
  }

}

class A2 extends A{}    

A2::wrapper();

get_called_class() prints A2 in both cases, even when I called the doprint method with self. why?

  • 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-13T04:44:09+00:00Added an answer on June 13, 2026 at 4:44 am

    get_called_class() always returns the class you actually call. You call A2:: so it’s A2.

    On my site there’s a tutorial with an LSB singleton abstract class. I’m not linking here because there’s always a zombie vigilante that comes and removes the links without even looking. But it’s in my description.

    The catch with LSB is that a method in A can call a method in B which can call a method in A back. See this example:

    header('Content-Type: text/plain'); // Pretty text output
    // LSB Parent
    class A {
        // NOLSB: Will call Current Class method
        static public function TriggerSelf() {
            self::OverrideMe();
        }
        // LSB: Will call Inheriting Class method (or Current if none Inherits)
        static public function TriggerStatic() {
            static::OverrideMe();
        }
        // Method to Override
        static public function OverrideMe() {
            echo 'A here', PHP_EOL;
        }
    }
    
    // LSB Child
    class B extends A {
        // Override by LSB
        static public function OverrideMe() {
            echo 'B here', PHP_EOL;
        }
    }
    
    A::TriggerSelf(); // <- NO LSB
    A::TriggerStatic(); // <- LSB (but not inheritance)
    
    B::TriggerSelf(); // <- NO LSB
    B::TriggerStatic(); // <- LSB (with inheritance, so it works)
    

    See how B::TriggerStatic() allows A to call a B method while B::TriggerSelf() calls a A method. That’s LSB. Parent class static methods can call child class static methods. It’s pretty much static abstracts 🙂

    Study the example, it’ll make sense.

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

Sidebar

Related Questions

Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
I don't know: if this works. if it's a good idea. what it is
don't know better title for this, but here's my code. I have class user
Don't know how to frase this but I found this code wich works as
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know why, but this code worked for me a month ago... maybe
Don't these two mean the same thing, first get the value and then increment?
Don't think that I'm mad, I understand how php works! That being said. I
Don't know if anyone can help me with this or if it's even possible.
Don't know why this doesn't work. I can't do implicit animation for a newly

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.