<?php
$sheldon = new DateTime('May 20th, 1980');
$neo = new DateTime('February 6th, 1979');
$today = new DateTimeImmutable();
$oneYearIntoTheFuture = $today->add(new DateInterval('P1Y'));
//since birthdays occur every year, the interval is one year
$interval = new DateInterval('P1Y');
//third argument is the end date, new DateTime() == right now
$period = new DatePeriod($neo, $interval, $today);
echo $today->format('d-m-Y'), PHP_EOL;
echo $oneYearIntoTheFuture->format('d-m-Y'), PHP_EOL;
echo PHP_EOL;
echo count($period), PHP_EOL;
foreach($period as $dt) {
//DateTime objects
echo $dt->format('Y-m-d - D'), "\n";
}
22-01-2015
22-01-2016
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, DatePeriod given in /in/O3otF:15
Stack trace:
#0 {main}
thrown in /in/O3otF on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.9
22-01-2015
22-01-2016
Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, DatePeriod given in /in/O3otF:15
Stack trace:
#0 {main}
thrown in /in/O3otF on line 15
Process exited with code 255.
Fatal error: Uncaught exception 'Exception' with message 'DatePeriod::__construct(): This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments.' in /in/O3otF:11
Stack trace:
#0 /in/O3otF(11): DatePeriod->__construct(Object(DateTime), Object(DateInterval), Object(DateTimeImmutable))
#1 {main}
thrown in /in/O3otF on line 11
Process exited with code 255.