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 Elephpant {
    private const HABITAT = 1;

    function trumpet() {
        // same as \Elephpant::C;
        return self::C;
    }
}

?>

Documentation

See Also