The self Keyword — a practical guide to PHP self keyword with clear examples you can reuse in real projects.
OOP Tutorial Series (34/65). Prefer one article? Read the complete OOP tutorial.
Short description
`self` refers to the class where it is written. For late static binding (inheritance-aware), use `static::`.
self vs static
class Base {
public static function who(): string { return self::class; }
public static function whoLate(): string { return static::class; }
}
class Child extends Base {}
echo Child::who(); // Base
echo Child::whoLate(); // Child