Class extension problem
| From: | Joshua Groboski | Date: | Tue, 05 Aug 2003 19:35:38 +0000 |
| Subject: | Class extension problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158340@lists.php.net to get a copy of this message | ||
Ok, I have a parent class (CMS) and a child class (WebSite extends CMS).
There is some important stuff going on in the constructor for CMS that I
think should be happening when I instantiate a new WebSite. Look at the
following example:
<?php
class CMS {
var $prop1 = "a";
function CMS(){
$this->prop1 = "A";
}
}
class WebSite extends CMS{
var $prop2 = "b";
function WebSite(){ }
function setProp2(){
$this->prop2 = $this->prop1;
}
}
$ws = new WebSite();
echo "Before: " . $ws->prop2 . " : " . $ws->prop1 . "\n";
$ws->setProp2();
echo "After: " . $ws->prop2 . " : " . $ws->prop1 . "\n";
?>
If you run this, you'll notice the constructor for CMS is never called. Is
this a by-design functionality, am I wrong about what I think should happen,
or am I just totally off my rocker?
--
Joshua Groboski
Programmer Analyst
SAVVIS Communications Inc.
http://www.savvis.net