Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the variable visibility error in this code? [closed]

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 ?

like image 900
Narayan Waraich Avatar asked Jan 03 '13 19:01

Narayan Waraich


1 Answers

You're getting the value of parent::c(), but you don't do anything with it. Use a return statement.

like image 138
greg0ire Avatar answered Nov 03 '22 01:11

greg0ire