Giving the following class for example (from http://swik.net/PHP/Object+Oriented+PHP),
Code: Select all
Class HelloWorld
{
public $word;
public function __construct($word)
{
$this->word = $word;
}
public function print()
{
echo $this->word;
}
}
class HelloWorld2 extends HelloWorld
{
}
$hello = new HelloWorld2('hello world');
$hello->print();So the final output will be:
hello world
and more
done
How could I do that?
thanks a lot
Got partial answer from
http://www.sitepoint.com/article/object-oriented-php/8
[...]
Please show me how to do the cascading constructors.
Code: Select all
Class HelloWorld
{
public $word;
public function __construct($word)
{
$this->word = $word;
}
public function dump()
{
echo $this->word;
}
}
class HelloWorld2 extends HelloWorld
{
public function __construct($word)
{
parent::__constructor($word);
$this->word .= "\nand";
}
public function dump()
{
parent::dump();
echo '\ndone';
}
}