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

Public Visibility

The public keyword is part of the three keywords to define visibility of a method, property or constant. It is the lowest level of visibility: it doesn’t restrict usage.

public is also the default visibility when it is omitted.

<?php

    class Elephpant {
        // public constant
        const HABITAT = 1;
        public $trunkLength = 2;
    }

    $elephpant = new Elephpant;
    echo $elephpant->trunkLength;
    echo Elephpant::HABITAT;

?>

Documentation

See Also