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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:32:14+00:00 2026-05-22T20:32:14+00:00

I was working on some PHP around the static:: keyword, and encountered an issue

  • 0

I was working on some PHP around the “static::” keyword, and encountered an issue where too many static calls result in confusion as to where a method resides. It’s easier to show by example:

class Class1
{
    function Test()
    {
        return Class2::Test();
    }
}

class Class2
{
    function Test()
    {
        return static::Test2();
    }

    function Test2()
    {
        return true;
    }
}

/* test 1: calling Class1::Test() statically results in expected call to Class2::Test2() */
echo "test 1: " . Class1::Test() . "\n";

/* test 2: instantiating the class causes Class1::Test2() to be called, which does not exist */
$Class1 = new Class1();
echo "test 2: " . $Class1->Test() . "\n";

I wanted to reach out and get opinions of PHP experts who can tell me whether this might be a genuine bug or simple misuse of the language.

I realize the setup may be odd with all the static calls, but it represents actual code that I came across.

Please let me know if any more information or clarification is needed. Thanks for any help in advance!

  • 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-22T20:32:15+00:00Added an answer on May 22, 2026 at 8:32 pm

    The PHP docs on late static bindings answer your question.

    “late static bindings work by storing the class named in the last “non-forwarding call”. In case of static method calls, this is the class explicitly named (usually the one on the left of the :: operator); in case of non static method calls, it is the class of the object. A “forwarding call” is a static one that is introduced by self::, parent::, static::” …

    Your test 1 is a static call, so when Class2::Test() is called, it stores Class2. The static test2 call refers to the correct place in Class2.

    Your test 2 is a non static call, so it uses the class of the object in all cases, and since it is a Class1, it can’t find the method Test2.

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

Sidebar

Related Questions

I'm working with some old PHP code that has a lot of the following:
I'm doing some PHP stuff on an Ubuntu server. The path I'm working in
In a PHP project I'm working on we need to create some DAL extensions
Okay so im working on this php image upload system but for some reason
I'm working on a script in PHP that needs to get some info from
I am a web-developer working in PHP. I have some limited experience with using
I'm currently working on my own PHP Framework, and I need some help figuring
When working with some open source projects (in my case Joomla and Moodle), I've
I have been working on some legacy C++ code that uses variable length structures
I'm working on some production software, using C# on the .NET framework. I really

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.