I am making a class to check for holidays. I made functions for specific holidays and an overarching function to see if a date is a holiday, not one in particular.
I am getting the following error:
Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\mgmt\classes\Holidays.php on line 52
Here is my code:
<?php
class Holidays {
//private member variables
private $date;
//constructors
public function Holidays() {
$this->$date = date("Y-m-d");
}
//setters
public function setDate($date) {
$this->$date = $date;
}
//getters
public function getDate() {
return $this->$date;
}
//member public functions
public function isNewYears($date) {
return ($date == date('Y', $date)."-01-01" ? true : false);
}
public function isMLKDay($date) {
return ($date == date("Y-m-d", strtotime("third Monday of January ".date('Y', $date)) ? true : false));
}
public function isValentinesDay($date) {
return ($date == date('Y', $date)."-02-14" ? true : false);
}
public function isPresidentsDay($date) {
return ($date == date("Y-m-d", strtotime("third Monday of February ".date('Y', $date)) ? true : false));
}
public function isEaster($date) {
return ($date == date("Y-m-d", easter_date($date)) ? true : false);
}
public function isMemorialDay($date) {
return ($date == date("Y-m-d", strtotime("last Monday of May ".date('Y', $date)) ? true : false));
}
public function isLaborDay($date) {
return ($date == date("Y-m-d", strtotime("first Monday of September ".date('Y', $date)) ? true : false));
}
public function isThanksgiving($date) {
return ($date == date("Y-m-d", strtotime("fourth Thursday in November".date('Y', $date)) ? true : false));
}
public function isChristmas($date) {
return ($date == date('Y', $date)."-12-25" ? true : false);
}
public function isHoliday($date) {
if (isNewYears($date))
else if (isMLKDay($date))
else if (isValentinesDay($date))
else if (isPresidentsDay($date))
else if (isEaster($date))
else if (isMemorialDay($date))
else if (isLaborDay($date))
else if (isThanksgiving($date))
else if (isChristmas($date))
else return false;
}
}
?>
It's throwing the error on the first else statement in isHoliday(). If that's not the proper structure then how should I do it?
else ifstatements have no bodies - and they don't. For clarify (and avoiding syntactic pitfalls) you should always use braces withifstatements.