I am a newbie to OOP in PHP and I am trying to create a small MVC structure for my website but I am stuck on an error which I am not able to figure out. My code is similar to the one given below :
class a
{
protected $b = "b";
protected function c()
{
return $this->b;
}
}
class d extends a
{
public function e()
{
parent::c();
}
}
$f = new d();
var_dump($f->e());
The output of this code is null, which I can't figure out !
In my original code I am storing my username and password in class 'a' and returning a PDO object in function 'c'.
What is the error here ?
You're getting the value of parent::c()
, but you don't do anything with it. Use a return statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With