du skal ikke bruge _GET eller _POST i en klasse
så skal du sende det med som parametere til functionen istedet, men tror du har forsøgt at få fat i $this->abc, istedet for $_GET["abc"]
måske du kunne tage udgangs punk i det her, godt nok antal dage.
- class Alder {
- protected $firstname, $secondname, $birth, $birth_year, $birth_month, $birth_day, $age, $timeToBirthday;
-
- public function __construct($iFirstname, $iSecondname, $iBirthYear, $iBirthMonth, $iBirthDay) {
- $this->firstname = $iFirstname;
- $this->secondname = $iSecondname;
- $this->birth = $iBirthYear . '-' . $iBirthMonth . '-' . $iBirthDay;
- $this->getAge();
- $this->timeToBirthday();
- }
-
- protected function getAge() {
- list($year, $month, $day) = explode("-", $this->birth);
- $year_diff = date("Y") - $year;
- $month_diff = date("m") - $month;
- $day_diff = date("d") - $day;
- if($month_diff < 0) {
- $year_diff--;
- } else if(($month_diff==0) && ($day_diff < 0)) {
- $year_diff--;
- }
- return $year_diff;
- }
-
- protected function timeToBirthday() {
- list($y,$m,$d) = explode("-", $this->birth);
- if(date("n") > $m && date("j") > $d){
- return $this->getDays($d, $m, date("Y")+1);
- }else{
- return $this->getDays($d, $m, date("Y"));
- }
- }
-
- private function getDays($d, $m, $y){
- $difference = mktime(0, 0, 0, $m, $d, $y, 0) - mktime();
- if ($difference < 0) { $difference = 0; }
- return floor($difference / 60/60/24 );
- }
-
- public function __toString() {
- return 'Hello '. $this->firstname . ' ' . $this->secondname . '.' .
- 'You are '. $this->getAge() . ' years old!<br />' .
- 'Days to your birthday '. $this->timeToBirthday();
- }
- }
der findes sikkeret en smartere måde, men kender den ikke lige