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

Properties

Class properties are variables, local to an object or a class.

Class properties might have visibility, chosen among: public, protected and private. public is the default.

Class properties might have an asymmetric visibility for writing, chosen among: public(set), protected(set) and private(set). By default, it is the same as the read visibility.

Class properties might have a default value. By default it is null.

Class properties might have a type, since PHP 7.4

Class properties might be readonly, for properties which are only set once, and cannot be modified.

Class properties might be static, and not related to an object, but to a class.

A property must be uniquely defined in a class. Class properties may be redefined in children or parent when the visibility allows it.

Properties are also called members.

<?php

    class X {
        private $property = 1;
    }

?>

Documentation

See Also