Reputation:
I just reviewed my code and I realize that I never use
var
However I read
http://www.php.net/manual/en/keyword.class.php
and it seems to say that one should use var.
<?php
class Cart {
var $items; // Items in our shopping cart
....blah
}
?>
In this example what privacy is var set to.
For my purposes I just normally do:
private $some_var;
public $some_var;
protected $some_var;
What is best practice?
Upvotes: 1
Views: 341
Reputation: 157
PHP4 used var. php4 had objects just like php5, but php5 did a much better job on working with and extending objects. Var is not required by any expression in php5 that I am aware of. They continued to allow its use because they had to allow old code in php4 to run on php5.
In php5 you use instead public,private,protected for all of your object variables. I believe VAR and public are the same thing technically, and var will be treated as a public variable.
Upvotes: 2
Reputation: 255005
var
is php4 only thing. For all php5 code you need to use proper visibility scope keywords.
Upvotes: 1
Reputation: 99687
var is identical to public. BUT most modern coding standards prefer 'public' over var.
Howevever, there is no real difference at all.
Upvotes: 3