This is probably a very trivial question, but I haven't been able to find the answer neither through web search engines, nor on php.net. Please just direct me to where I can read about this, if you haven't got time to explain.
- What does the 'var' keyword mean in PHP?
- Are there any differences between PHP4 and PHP5?
here and now in
2018
usingvar
for variable declaration is synonymous withpublic
as inAnswer: From php 5.3 and
>
, thevar
keyword is equivalent topublic
when declaring variables inside a class.is the same as (for php 5.3 and
>
):History: It was previously the norm for declaring variables in classes, though later became depreciated, but later (PHP 5.3) it became un-depreciated.
So basically it is an old style and do not use it for newer version of PHP. Better to use Public keyword instead;if you are not in love with var keyword. So instead of using
Use
The
var
keyword is used to declare variables in a class in PHP 4:With PHP 5 property and method visibility (
public
,protected
andprivate
) was introduced and thusvar
is deprecated.It's for declaring class member variables in PHP4, and is no longer needed. It will work in PHP5, but will raise an
E_STRICT
warning in PHP from version 5.0.0 up to version 5.1.2, as of when it was deprecated. Since PHP 5.3, var has been un-deprecated and is a synonym for 'public'.Example usage:
var is used like public .if a varable is declared like this in a class var $a; if means its scope is public for the class. in simplea words var ~public