Jared Drake
Jared Drake

Reputation: 1002

PHP inheritance issue

I googled for this for quite awhile. I think I am missing some big concept, but I can't figure out why this won't work

//SomeClass.php

class SomeClass 
{
    protected $something;
    public function __construct() {
        $this->something = 'password';
    }
    public function test() {
        return ($this->something);
    }
}

//OtherClass.php

require_once('SomeClass.php');
class OtherClass extends SomeClass
{   
    public function __construct() {
        echo parent::test();
    }
}

What is the deal here?

Upvotes: 0

Views: 67

Answers (2)

Yossi Ben Haim
Yossi Ben Haim

Reputation: 190

You should call parent::__construct() before calling parent::test()

Upvotes: 6

Valera Leontyev
Valera Leontyev

Reputation: 1181

Constructor must not return any value.

Upvotes: 0

Related Questions