Removed in oop class
-
There's a class in it.
protected $_host, $_login, $_password, $_port; function __construct($config = array()) { $app = JFactory::getApplication('site'); $componentParams = $app->getParams('com_test'); $this->_host = $componentParams->get('host'); $this->_login = $componentParams->get('login'); $this->_password = $componentParams->get('password'); $this->_port = $componentParams->get('port'); parent::__construct($config); }
Then I'm writing a function.
private static function Conetc() { var_dump($this->_host); //Fatal error: Using $this when not in object context in }
The question is how to declare variables so that they can be seen in functions. ♪ ♪ ♪
-
You've declared a function.
Conetc
As a statistical function.private static function Conetc() ^^^^^^
It is caused by an irrelevant class object, so it does not have access to non-static class variables.
Either declare a function as non-static or give it as an argument of class object.