Why use VAR in PHP?

8

Why use VAR in php if we can declare variables without VAR?

We can do this: $teste so why do that? var $teste

For example, is it the same thing I do this?

class Caneta {
    var $modelo;
    var $cor;
}

And this:

class Caneta {
     $modelo;
     $cor;
}
    
asked by anonymous 09.06.2017 / 15:42

1 answer

8

TL; DR

  

Do not use var to declare class properties this was used in php4.

The keyword var was used in php4 to define a property in a class. From php5 its use was advised instead one must use some of the access modifiers: public , protected or private .

In the code example it is the same thing both properties will be accessible by all or it is equivalent to public . By default if the access modifier is omitted its visibility will be public this is valid for methods as well.

Recommended reading:

Attribute x Attribute

    
09.06.2017 / 15:46