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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:02:12+00:00 2026-05-13T06:02:12+00:00

Starting with version 5.3, PHP supports late binding for static methods. While it’s an

  • 0

Starting with version 5.3, PHP supports late binding for static methods. While it’s an undoubtedly useful feature, there are only several cases where its use is really necessary (e.g. the Active Record pattern).

Consider these examples:

1. Convenience constructors (::create())

class SimpleObject
{
    public function __construct() { /* ... */ }

    public static function create()
    {
        return new static; // or: return new self;
    }
}

If this class may be extended (however, it’s not extended by any class in the same package), should late static binding be used just to make extending it easier (without having to rewrite the ::create() method, and, more importantly, without having to remember to do that)?

Note: this idiom is used to work around the impossibility to call methods on just constructed objects: new SimpleObject()->doStuff() is invalid in PHP.


2. Class constants

class TagMatcher
{
    const TAG_PATTERN = '/\<([a-z\-]+?)\>/i';

    private $subject;

    public function construct($subject) { $this->subject = $subject; }

    public function getAllTags()
    {
        $pattern = static::TAG_PATTERN;
        preg_match_all($pattern, $this->subject);
        return $pattern[1];
    }
}

The reason to use static:: in this example is similar to the previous one. It’s used just because this class can be made to match differently formed tags just by extending it and overriding the constant.


So, to wrap it all up, are these uses (and similar ones) of late static binding are an overkill? Is there any noticeable performance hit? Also, does frequent use of late binding reduce the overall performance boost given by opcode caches?

  • 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-13T06:02:12+00:00Added an answer on May 13, 2026 at 6:02 am

    So, to wrap it all up, are these uses (and similar ones) of late static binding are an overkill? Is there any noticeable performance hit? Also, does frequent use of late binding reduce the overall performance boost given by opcode caches?

    The introduction of late static binding fixes a flaw in PHP’s object model. It’s not about performance, it’s about semantics.

    For example, I like to use static methods whenever the implementation of the method doesn’t use $this. Just because a method is static doesn’t mean to say that you don’t want to override it sometimes. Prior to PHP 5.3, the behavior was that no error was flagged if you overrode a static method, but PHP would just go ahead and silently use the parent’s version. For example, the code below prints ‘A’ before PHP 5.3. That’s highly unexpected behavior.

    Late static binding fixes it, and now the same code prints ‘B’.

    <?php
    class A {
      public static function who() {
        echo __CLASS__;
      }
      public static function test() {
        static::who();
      }
    }
    
    class B extends A {
      public static function who() {
        echo __CLASS__;
      }
    }
    
    B::test();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting with version 2.2 Doctrine has Paginator . There is only one example in
$ sudo service memcached start Starting memcached: memcached. $ php-shell.sh PHP-Shell - Version 0.3.1,
Quote from hib official docs: Starting with version 3.0.1, Hibernate added the SessionFactory.getCurrentSession() method.
I am just now starting to use version control and my head is spinning!
Starting with a recent new version of ADT, I've noticed this new attribute on
Starting with API level 9, there's android:filterTouchesWhenObscured attribute and corresponding setFilterTouchesWhenObscured method on ViewGroup
I'm starting a new CodeIgniter project, so I grabbed a fresh copy of version
I'm using PHP Markdown (version 1.0.1n, updated October 2009) to display text saved to
So I'm starting a web project from scratch on PHP/Zend Framework/SVN, and want to
Is there any PHP PDF library that can replace placeholder variables in an existing

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.