PHP class: Global variable vs Accessbale varibales

This question already has an answer here:

  • What does PHP keyword 'var' do? 7 answers

  • The keyword before variable name defines the visibility of the variable. It defines the access rights for the particular variable.

    var

    When using var , it will be publicly accessible through out your project same as public .

    protected

    When using protected , variable is only accessible for the classes which extends parent class for particular page only.

    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.

    Read More Here

    链接地址: http://www.djcxy.com/p/96552.html

    上一篇: 我应该在类或构造函数中放置变量吗? PHP

    下一篇: PHP类:全局变量与Accessbale varibales