adding more oo bits to the class/oop exercise

cat-town
Dan Buch 14 years ago
parent f90e4222b6
commit 426f516ec9

@ -5,11 +5,20 @@ mkheader("classes!", '#8bb');
class html { class html {
private $contents = "";
private $heading = "";
public $br = "<br />"; public function __construct($heading) {
$this->heading = $heading;
}
public function addparagraph($message) {
$this->contents .= ("<p>" . $message . "</p>\n");
}
public function printline($message) { public function show() {
printf("%s%s\n", $message, $this->br); print "\n\n<h1>" . $this->heading . "</h1>\n";
print $this->contents;
} }
} }
@ -19,8 +28,20 @@ class html {
<body> <body>
<?php <?php
$page = new html(); $elvis = new html("Elvis ist rad");
$page->printline("This is some text, eh?"); $goth = new html("Goth Poetry ist rad");
$elvis->addparagraph("Welcome to my Elvis Fan Page! Uh-huh, uh-huh, uh-huh.");
$elvis->addparagraph("Do you love Elvis? Yes! Yes you do!");
$goth->addparagraph("Enter thee into the Goth Poetry Labyrinth of Spooooky Dooooom...");
$goth->addparagraph("Many terribly terrifying poems await thee.");
$elvis->show();
printf("\n<p style='border-bottom:3px solid #222;'></p>\n");
$goth->show();
?> ?>
</body> </body>

Loading…
Cancel
Save