Moin zusammen,
ich habe mir mal ein bisschen OOP angeschaut da ich von der strukturierten Programmierung wegkommen möchte und die Vorteile von OOP nutzen möchte.
Also ich habe eine kleine "Übungsseite" gebaut um mich etwas in sachen OOP auszutoben, da werden nach Zufall typische 1337 Wörter ausgegeben... Funzt ja auch alles
Meine Frage ist nur: Was könnte ich OOP technisch besser machen?
Ich bin mir sicher, dass das alles nicht so konform ist wie es sein sollte
Also bitte sagt mir was an dem Code ungünstig ist
Das ganze kann man übrigenz da betrachten: http://decstasy.de/lol
Danke, LG Decs schonmal
Die index.php
PHP
<?php
// Includes
include_once "class/RenderZeit.class.php";
include_once "class/fun.class.php";
// RenderZeit sagen, dass es existieren darf :)
$RenderZeit = new RenderZeit();
$RenderZeit->anfang();
// HTML Bla Bla
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n"
.' <html>'."\n"
.' <head>'."\n"
.' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'."\n"
.' <title>L0L</title>'."\n"
.' </head>'."\n"
.' <body bgcolor="#333333">'."\n";
// Aufruf ^.^
$fun = new fun();
echo $fun->lol(50,5,140);
// RenderZeit...
$RenderZeit->ende();
echo " <br />"."\n"
." <a style=\"font-family: arial ,tahoma; font-size: 10px; color: rgb(150,150,150)\">"
."Die Erzeugung dieser Webseite hat "
.$RenderZeit->ergebniss()
." Sekunden gedauert."
."</a>"."\n";
// Nochmal HTML Bla Bla
echo ' </body>'."\n"
.'</html>';
?>
Alles anzeigen
Die fun.class.php
PHP
<?php
class fun{
private $result = NULL;
public function lol($AnzWörter, $AnzBlöcke, $TextAlpha) {
for($i = (int)0; $i < (int)$AnzBlöcke; $i++) { // Wortblöcke
for($b = (int)0; $b < (int)$AnzWörter; $b++) { // Wortausgabe
// Anzuzeigende Wörter
$wort = array("LOL", "WTF", "xD", "ROFL", "1337", "OMFG", "LeeT", "<3", "HDGDL", "KMH", "OMG",
"AFK", "HDF", "bg", "ip?", "css?", "WB", "RE", "FB", "w8", "WTH", "w00t", "TTYL", "TMI", "TBH",
"SuFu", "RTFM", "RL", "RE", "PLONK", "POV", "PPL", "O RLY?", "NSY"
);
// Damit die Schrift für den Hintergrund nicht zu Dunkel wird
$schnitt = (int)0;
while($schnitt <= (int)$TextAlpha){ // Ich weiß, dass das BruteForce artig ist...
$col['R'] = (int)rand(0,255);
$col['G'] = (int)rand(0,255);
$col['B'] = (int)rand(0,255);
$schnitt = ($col['R'] + $col['G'] + $col['B']) / 3;
}
// HTML Variable
$this->result .= " <a style=\"font-family: arial ,tahoma; font-size:16px; color: rgb("
.$col['R'].",".$col['G'].",".$col['B']
.");\">"
.$wort[rand(0,count($wort))]
."</a>\n";
}
// Zeilenumbruch
$this->result .= " <br />"."\n";
}
return $this->result; // Rückgabe
}
}
?>
Alles anzeigen
Und die RenderZeit.class.php
PHP
<?php
class RenderZeit{
private $Anfangszeit;
private $Endzeit;
private $result = NULL;
private function getmicrotime(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
public function anfang(){
$this->Anfangszeit = $this->getmicrotime();
return $this->Anfangszeit;
}
public function ende(){
$this->Endzeit = $this->getmicrotime();
return $this->Endzeit;
}
public function ergebniss(){
$this->result = number_format($this->Endzeit-$this->Anfangszeit, 4, ",", ".");
return $this->result;
}
}
?>
Alles anzeigen