I'm trying to store the value from the class below as a variable, so i could used it later on, but I can't get it working.
Any ideas?
class Dates {
public function __construct($date) {
$this->DateCompare($date);
}
public function DateCompare($date) {
$date1 = new DateTime("2015-04-08");
$date2 = new DateTime($date);
$diff=date_diff($date1,$date2);
return $diff->format("%a");
}
}
echo $test = new Dates("2015-05-04");
Error I'm getting: Catchable fatal error: Object of class Dates could not be converted to string in /virtual/index.php
As said before, I don't want to echo that out, just store it in the $test
variable, but if I can't even echo that out, then I'm not storing it either.