From 426f516ec9f8af8ed1a66b71e669079719f6bbc4 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 1 Jan 2011 13:40:24 -0500 Subject: [PATCH] adding more oo bits to the class/oop exercise --- docroot/html/classes.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/docroot/html/classes.php b/docroot/html/classes.php index 8aa2c59..e259735 100644 --- a/docroot/html/classes.php +++ b/docroot/html/classes.php @@ -5,11 +5,20 @@ mkheader("classes!", '#8bb'); class html { + private $contents = ""; + private $heading = ""; - public $br = "
"; + public function __construct($heading) { + $this->heading = $heading; + } + + public function addparagraph($message) { + $this->contents .= ("

" . $message . "

\n"); + } - public function printline($message) { - printf("%s%s\n", $message, $this->br); + public function show() { + print "\n\n

" . $this->heading . "

\n"; + print $this->contents; } } @@ -19,8 +28,20 @@ class html { printline("This is some text, eh?"); + $elvis = new html("Elvis ist rad"); + $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

\n"); + + $goth->show(); ?>