Consider the following situation
class URISplit {
var $REQ_URI;
//some more variables
function __construct($uri) {
//some code
$this->REQ_URI = $uri;
//some code yet again
}
}
and the following
class URIResolve extends URISplit {
//some variables
function __construct($uri) {
//some code
}
}
and another
class PageControl extends URIResolve {
//some variables
function __construct($uri) {
//some more code
}
}
and now the following statement
$page = new PageControl($_SERVER['REQUEST_URI']);
will this statement ensure the proper construction of all classes.
In other words, will constructors of class URISplit
and class URIResolve
use the string supplied to class PageControl
's constructor, and do the proper construction.
My Objective is to just create an object of class PageControl
and relax and see it do the work. Work means ->
class URISplit
)class URIResolve
)class PageControl
Phew! Long question!
You should explicitly call the parent constructor from the child's one. Take a look at this site for an example.
The reason is that the child class may choose to give the parent constructor some different arguments.
Heck, it's even possible to have an
class SOSplit extends URISplit {
function __construct() {
parent::__construct( "http://stackoverflow.com" );
}
}
class URIResolve extends URISplit {
//some variables
function __construct($uri) {
parent::__construct( $uri);
}
}
I think you should add calls to the parent constructor as described in http://php.net/manual/en/language.oop5.decon.php
class SubClass extends BaseClass {
function __construct() {
parent::__construct();
print "In SubClass constructor
";
}
}