Muss ein kleinen Terminplaner erstellen und habe erst Mal eine Klasse geschrieben. Nun ich wollte die toString() Methode testen, es kommt jedoch nicht der erwartete Wert raus.
Hier ist mein Code:
Kann mir jemand da helfen? Wieso kommt nicht "19.12.2013 17 : 30" raus, sondern "0.0 0 : 00"?
Hier ist mein Code:
PHP-Code:
<?php
class Termin {
private $year;
private $month;
private $day;
private $hour;
private $addhalf;
private $free;
private $termin = "";
public function __Termin($year, $month, $day, $hour, $addhalf, $free) {
$this->year = $year;
$this->month = $month;
$this->day = $day;
$this->hour = $hour;
$this->addhalf = $addhalf;
$this->free = $free;
}
public function getYear() {
return $year;
}
public function getMonth() {
return $month;
}
public function getDay() {
return $day;
}
public function getHour() {
return $hour;
}
public function getAddHalf() {
return $addhalf;
}
public function isFree() {
return $free;
}
public function setFree() {
$free = true;
}
public function lock() {
$free = false;
}
function toString() {
if ($this->day < 10) {
$this->termin .= "0" . (string)$this->day;
} else {
$this->termin .= (string)$this->day;
}
$this->termin .= ".";
if ($this->month < 10) {
$this->termin .= "0" . (string)$this->month;
} else {
$this->termin .= (string)$this->month;
}
$this->termin .= ".";
$this->termin .= (string)$this->year;
$this->termin .= " ";
if ($this->hour < 10) {
$this->termin .= "0";
}
$this->termin .= (string)$this->hour;
$this->termin .= " : ";
if ($this->addhalf) {
$this->termin .= "30";
} else {
$this->termin .= "00";
}
return $this->termin;
}
}
$t = new Termin(2013, 12, 19, 17, true, true);
echo ($t->toString());
?>
Kommentar