Language PHP5
(another version)
Date: | 05/17/05 |
Author: | Kenneth Clark |
URL: | n/a |
Comments: | 4 |
Info: | n/a |
Score: | ![]() |
class SingBeerWallSong{ private $noBeers; private $output; private $outputType; public function __construct($noBeers, $type){ $this->noBeers = $noBeers; $this->type = $type; } public function singSong(){ for ($i = $this->noBeers; $i > 0; $i--){ if ($i == 1) { $bottle = "bottle"; }else{ $bottle = "bottles"; } $this->output .= $i . " ".$bottle." of beer on the wall \n"; $this->output .= $i . " ".$bottle." of beer \n"; $this->output .= "And if 1 bottle of beer should fall,\n"; if ($this->minusOne($i) == 1) { $bottle = "bottle"; }else{ $bottle = "bottles"; } $this->output .= "There will be " . $this->minusOne($i) . " " . $bottle . " of beer on the wall \n\n"; } if (strtolower($this->type) == "html") { $this->addBreak(); } } private function addBreak(){ $this->output = str_replace("\n","<br>",$this->output); } private function minusOne($int){ return $int - 1; } public function getOutput(){ return $this->output; } } $oBeer = new SingBeerWallSong(99,"html"); $oBeer->singSong(); echo $oBeer->getOutput();
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Objects, phpdoc comments, exceptions | Dave Marshall | 09/22/05 | 9 | ![]() ![]() |
PHP5 code using classes | Tim M | 09/02/05 | 9 | ![]() ![]() |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
it seems to be based on the Builder Design Pattern philosophy
1st it is not oo, but structured ... just thrown some functions into a useless class
2nd bad style, ineffective
3rd boring
ps when using php5 you might consider using the __toString method.