What does PHP keyword 'var' do? What does PHP keyword 'var' do? php php

What does PHP keyword 'var' do?


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:

class foo {    var $x = 'y'; // or you can use public like...    public $x = 'y'; //this is also a class member variables.    function bar() {    }}


The var keyword is used to declare variables in a class in PHP 4:

class Foo {    var $bar;}

With PHP 5 property and method visibility (public, protected and private) was introduced and thus var is deprecated.


I quote from http://www.php.net/manual/en/language.oop5.visibility.php

Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.