tags:

views:

7141

answers:

4

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.

  1. What does the 'var' keyword mean in PHP?
  2. Are there any differences between PHP4 and PHP5?
+26  A: 

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 PHP5 up to version 5.3, as of which it has been deprecated. Example usage:

class foo {
    var $x = 'y';
    function bar() {
    }
}
karim79
It raises no E_STRICT in PHP 5.3 though.
Ionuț G. Stan
Thanks Ionut, I did not know that, will edit the answer.
karim79
Thanks for a fast vigorous answer.
joelpet
+5  A: 

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.

Gumbo
In PHP 5.3 `var` is de-deprecated :)
Ionuț G. Stan
Thanks for your answer! If it was possible to mark multiple answers as accepted I would have marked this one too.
joelpet
A: 

You should consult the PHP reference on their website, php.net.

Here is the section that describes variable declarations: http://us2.php.net/manual/en/language.variables.php

spoulson
I've been all through php.net and haven't found an explanation like the accepted answer here...
Zack
Even if you didn't find the exact answer to your particular problem, I'm certain you learned SOMETHING from PHP's online docs.
spoulson
Or at LEAST from all the comments streaming away at the bottom ...
Smandoli
A: 

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.