Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
OOP

The self Keyword

Reference the current class with self:: for static members and constants.

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

Leave a reply

Your email address will not be published. Required fields are marked *