self:: vs static:: in PHP

self:: always refers to the class where it's written; static:: resolves to the actual called class at runtime, enabling late static binding.

Published September 18, 2026

self:: refers to the class in which the code is literally written, resolved at compile time. static:: refers to the class that was actually called at runtime — a feature called late static binding — which matters when a method is inherited by a subclass.

Common causes

  • Before PHP 5.3, self:: was the only option, which caused problems in inheritance: a parent class method using self::create() would always instantiate the parent class, even when called on a child class

How to fix it

  • Use static:: in factory-style methods so subclasses that inherit the method create an instance of themselves, not the parent
  • Use self:: when you deliberately want to always reference the defining class, regardless of which subclass calls the method
  • This distinction only matters inside inherited methods — outside of inheritance, self:: and static:: behave identically

Example

class Model {
    public static function create(): static {
        return new static();
    }
}
class User extends Model {}

User::create(); // returns a User instance because of static::

FAQ

Which one should I default to?

In most modern PHP code (especially base/factory classes meant to be extended), static:: is the safer default since it respects the actual called class.

More PHP articles