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

Var

var keyword for introducing PHP properties in classes. It originates from PHP 4, where it was the only way to declare class properties. Since PHP 5, visibility keywords like public, private, protected replaced it as the idiomatic syntax.

var is equivalent to public: a property declared with var is publicly accessible. It is considered legacy syntax and is not recommended.

Modern property declarations support additional modifiers unavailable with var, such as final, static, readonly, and type declarations.

var may be omitted with other options such as final, static, readonly, or asymmetric visibility: then, the property is publicly accessible.

<?php

    class Elephpant {
        var $tusk;   // public $tusk
        final $ivory; // public final $ivory;
    }

?>

Documentation

See Also