I want to extend the DateInterval
class to add my own methods. For this I want to create an instance of the DateIntervalEx
extension class from a DateInterval
object.
Example:
$dateInterval = date_create('yesterday')->diff(date_create('today 13:24'));
$diEx = new DateIntervalEx($dateInterval);
My attempt for the class:
class DateIntervalEx extends Dateinterval{
public function __construct(DateInterval $interval){
parent::__construct('P0D');
foreach($interval as $prop => $value){
$this->$prop = $value;
}
}
}
The diff()
method returns a DateInterval
with $days == 1
DateInterval::__set_state(array(
'y' => 0,
'm' => 0,
'd' => 1,
'h' => 13,
'i' => 24,
's' => 0,
'f' => 0.0,
'weekday' => 0,
'weekday_behavior' => 0,
'first_last_day_of' => 0,
'invert' => 0,
'days' => 1,
'special_type' => 0,
'special_amount' => 0,
'have_weekday_relative' => 0,
'have_special_relative' => 0,
))
But my extension class returns days => false.
DateIntervalEx::__set_state(array(
'weekday' => 0,
'weekday_behavior' => 0,
'first_last_day_of' => 0,
'days' => false,
'special_type' => 0,
'special_amount' => 0,
'have_weekday_relative' => 0,
'have_special_relative' => 0,
'y' => 0,
'm' => 0,
'd' => 1,
'h' => 13,
'i' => 24,
's' => 0,
'f' => 0.0,
'invert' => 0,
))
How can I set the days property to the correct value?