Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Self

self is one of the three special keywords that are used to access properties or methods from inside the class definition. It relates to the current written class.

self is traditionally written lower-case, although it is case-insensitive. self is a PHP keyword.

<?php

class X {
    private const X = 1;
    
    function foo() {
        // same as \X::C;
        return self::C;
    }
}

?>

Documentation

See Also