I'm using PHP's new(ish) Date classes for a calendar/scheduler I'm developing. I am trying to extend DateInterval so that I limit the interval to particular sizes like 1 year, 1 month, 1 week or 1 day. The extended class would be used to help generate the calendar view.
I'm getting the PHP error: Unknown property (days) when I run the following method.
private function adjust(){
//to zero all the DateInterval properties except the one I want
$adjustments = array ('y'=>0, 'm'=>0, 'd'=>0,
'h'=>0, 'i'=>0, 's'=>0,
'invert'=>0, 'days'=>0);
if($this->y>=1 || $this->days>180){
$adjustments['y']=1; //1 year
} else if ($this->m>6){
$adjustments['y']=1; //1 year
} else if ($this->m>=1){
$adjustments['m']=$this->m; //multiple months less than 6
} else if ($this->d>7){
$adjustments['m']=1; //1 month
} else if ($this->d>1){
$adjustments['d']=7; //1 week
} else {
$adjustments['d']=1; //1 day
}
foreach($adjustments as $k=>$v){
$this->$k=$v; //reset all the class properties
}
}
Any idea why? As far as the documentation seems to suggest, 'days' should be valid.