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:: always refers to the class where the code is written, while static:: refers to the class that was actually called at runtime (late static binding). Use static:: when subclasses should be able to override the result.
The concept
self is resolved at compile time to the defining class. A method written in Parent that uses self::create() will always build a Parent, even when called on Child.
static is resolved at runtime to the class used in the call, so Child::make() with new static() produces a Child.
Who gets created?
Practical examples
The difference
class Parent_ {
public static function viaSelf() { return new self(); }
public static function viaStatic() { return new static(); }
}
class Child extends Parent_ {}
get_class(Child::viaSelf()); // Parent_
get_class(Child::viaStatic()); // ChildFluent factory
abstract class Model {
public static function make(array $a): static {
$m = new static();
foreach ($a as $k => $v) $m->$k = $v;
return $m;
}
}Constants
class A { const NAME = 'A'; function who() { return static::NAME; } }
class B extends A { const NAME = 'B'; }
(new B)->who(); // 'B'Common mistakes
- Using self:: in a base class factory and wondering why subclasses are not returned.
- Using static:: for private constants that must stay fixed.
- Confusing static:: with the static keyword on properties.
Key takeaways
- self = defining class, static = called class.
- Use static for overridable factories and constants.
- Use self when behaviour must not change.
FAQ
What is late static binding?
Resolving static:: at runtime instead of at definition, so inheritance affects the result.
Does parent:: matter here?
parent:: calls the immediate parent class explicitly.