3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; }
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
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.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
22-01-2015 22-01-2016 Warning: count(): Parameter must be an array or an object that implements Countable in /in/O3otF on line 15 1 1979-02-06 - Tue 1980-02-06 - Wed 1981-02-06 - Fri 1982-02-06 - Sat 1983-02-06 - Sun 1984-02-06 - Mon 1985-02-06 - Wed 1986-02-06 - Thu 1987-02-06 - Fri 1988-02-06 - Sat 1989-02-06 - Mon 1990-02-06 - Tue 1991-02-06 - Wed 1992-02-06 - Thu 1993-02-06 - Sat 1994-02-06 - Sun 1995-02-06 - Mon 1996-02-06 - Tue 1997-02-06 - Thu 1998-02-06 - Fri 1999-02-06 - Sat 2000-02-06 - Sun 2001-02-06 - Tue 2002-02-06 - Wed 2003-02-06 - Thu 2004-02-06 - Fri 2005-02-06 - Sun 2006-02-06 - Mon 2007-02-06 - Tue 2008-02-06 - Wed 2009-02-06 - Fri 2010-02-06 - Sat 2011-02-06 - Sun 2012-02-06 - Mon 2013-02-06 - Wed 2014-02-06 - Thu
Output for 5.5.8 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25
22-01-2015 22-01-2016 1 1979-02-06 - Tue 1980-02-06 - Wed 1981-02-06 - Fri 1982-02-06 - Sat 1983-02-06 - Sun 1984-02-06 - Mon 1985-02-06 - Wed 1986-02-06 - Thu 1987-02-06 - Fri 1988-02-06 - Sat 1989-02-06 - Mon 1990-02-06 - Tue 1991-02-06 - Wed 1992-02-06 - Thu 1993-02-06 - Sat 1994-02-06 - Sun 1995-02-06 - Mon 1996-02-06 - Tue 1997-02-06 - Thu 1998-02-06 - Fri 1999-02-06 - Sat 2000-02-06 - Sun 2001-02-06 - Tue 2002-02-06 - Wed 2003-02-06 - Thu 2004-02-06 - Fri 2005-02-06 - Sun 2006-02-06 - Mon 2007-02-06 - Tue 2008-02-06 - Wed 2009-02-06 - Fri 2010-02-06 - Sat 2011-02-06 - Sun 2012-02-06 - Mon 2013-02-06 - Wed 2014-02-06 - Thu
Output for 5.5.0 - 5.5.7
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.
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
Fatal error: Class 'DateTimeImmutable' not found in /in/O3otF on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/O3otF on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/O3otF on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/O3otF on line 2

preferences:
252.22 ms | 401 KiB | 424 Q