Inheriting a constructor of an abstract class

I have an abstract class with a constructor that takes an argument representing a db link object. I also have a need to create a constructor object in the derived class.

What I tried was to declare the constructor in the derived class, do what I want to do and then call parent:__construct(). That works fine except I don’t get the link object. It looks like this

Abstract class


	function __construct($link = NULL) {
		if (condition) {
			do this
		}
		$this->link = $link;
		$this->loadPage();
	}

Derived class


		function __construct() {
			if (condition) {
				do this;
			} else {
				parent::__construct();
			}
		}

When I called parent::__construct() I didn’t have access to $link. To make it work I ended up with the following in the derived class


	function __construct($link = NULL) {
		if (condition) {
			do this
		} else {
			$this->link = $link;
			$this->loadPage();
		}
	}
	

This works but it bypasses the parent constructor entirely. My question is one of understanding. In a simple situation like this, it’s no problem to repeat the code, but why is it that I’m not getting access to the link object in the derived class doing it the way I did it originally? Thanks

So why didn’t you do this…? (Using your pseudo-code…)


		function __construct($link = NULL) {
			if (condition) {
				do this;
			} else {
				parent::__construct($link);
			}
		}

That works and now I understand how it works and why it was doing what it was. Thanks much.