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 X {
var $y; // public $y
final $z; // public final $z;
}
?>
Related : Visibility, Protected Visibility, Private Visibility, Public Visibility, Properties, static, Final Keyword, Readonly, Property Type Declaration, Promoted Properties, Asymmetric Visibility, OOP (Object Oriented Programming), Dynamic Properties, Legacy