Declaring class variables question

What do these var declarations actually do inside of a PHP class:

class VbForumsPageMain extends BxDolPageView {
    var $_oMain;
    var $_oTemplate;
    var $_oConfig;
    var $_oDb;

    function VbForumsPageMain(&$oMain) {
        $this->_oMain = &$oMain;
        $this->_oTemplate = $oMain->_oTemplate;
        $this->_oConfig = $oMain->_oConfig;
        $this->_oDb = $oMain->_oDb;
        parent::BxDolPageView('vb_forums_main');
    }
}

Are they neccessary and do they add any extra use to the variables? I'm not sure whey they're in the class twice.


The first use is defining them, the second is initialising them. It's good practice to define them up front and even better practice to set the appropriate visibility .

Have a read of the PHP documentation for more information - what you learn now will put you in good stead for the future.


This has been answered here, hope it helps - What does PHP keyword 'var' do?.

It basically declares public properties or the class, but you should use private , public and protected instead.


Yes, they are needed as they define the extension of the class. The VbForumsPageMain class has the same properties (variables) as the BxDolPageView extended by those vars. The function below sets the values and the structure of the class.

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

上一篇: PHP:简单的代码验证失败

下一篇: 声明类变量的问题