0

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?

1
  • It just doesn't output anything. I would think it should output "password" Commented Dec 15, 2012 at 20:07

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

Right. Manual excerpt: Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.
ARGH!!!!!!! Thanks a ton! You're a champ. God bless you. I really should read the manual better, but it's a touch too boring.
0

Constructor must not return any value.

1 Comment

Ya, sorry, that was a typo. I updated the answer and it still doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.