why it uses the Constructor?
Posted: Sat Aug 14, 2010 3:30 am
class 1:
class 2:
i don't know why in class 2 it uses a construct function. i feel it is unnecessary .any tips would be appreciated.
Code: Select all
class HelloWorld
{ public $world;
function getHtml()
{ return "<html><body>". "Hello, ".$this->world."!". "</body></html>"; } }
Code: Select all
class HelloWorld {
public $world;
function __construct($world) {
$this->world = $world;
}
function getHtml() {
return "<html><body>".
"Hello ".$this->world."!".
"</body></html>";
}
}