I have a weird problem in PHP. I have two classes, one extending another. The problem is that i when I try to access a variable in the parent class (via a getVar()
method), it returns undefined
, even though it had been already defined in the parent's constructor.
class HttpClient
{
private $errorList;
public function __construct()
{
$errorList = [];
}
public function getHttpErrorList() { return $errorList; }
//...
}
class Twitter extends HttpClient
{
public function __construct()
{
parent::__construct();
//..
}
public function getMessages()
{
//...
var_dump($this->getHttpErrorList()); //returns undefined variable!
}
What is the cause of this problem and how do I solve it?