What is the difference between var $ var and public $ var?

4

I have a class:

class anyClass{
   public $var1;
   var $var2;
}

What's the difference between $ var1 and $ var2?

    
asked by anonymous 13.07.2015 / 06:31

3 answers

6

public $var1 is a public member of the class access modifiers have been added in php5.

Manual - visibility

    
13.07.2015 / 06:34
0

The variable declared as var $var2; has been deprecated since the php4 version. From php5, it was possible to modify the access of the attributes and methods of the class to allow a more performative reach of the objects, through inheritances, access restrictions, polymorphism, among other good practices in the use of PHP language.

    
13.07.2015 / 15:09
0

It was a way of declaring itself an attribute with public. It has been deprecated since PHP version 5.

Example of public attribute declaration using PHP version 4 or lower (prefix var ).

<?php
    classe Caneta {
        var $modelo;
        var $cor; 
    }

Currently, to declare an attribute as public, you should use the prefix public instead of var , see how the same example would be with PHP 5 or higher:

<?php
    classe Caneta {
        public $modelo;
        public $cor; 
    }
    
02.09.2016 / 06:57