3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class PeriodIterator * * @author Efimov Evgeniy <evgeniy.efimov@alpari.org> */ class PeriodIterator implements \Iterator { /** * Start date * * @var \DateTime */ private $startDate; /** * End date * * @var \DateTime */ private $endDate; /** * Iteration offset * * @var string */ private $offset; /** * Current iteration date * * @var \DateTime */ private $currentDate; /** * PeriodIterator constructor. * * @param \DateTime $startDate Start date * @param \DateTime $endDate End date * @param string $offset Offset for iteration */ public function __construct(\DateTime $startDate, \DateTime $endDate, $offset) { $this->startDate = $startDate; $this->endDate = $endDate; $this->offset = $offset; } /** {@inheritdoc} */ public function current() { return $this->currentDate; } /** {@inheritdoc} */ public function next() { $this->currentDate->modify($this->offset); } /** {@inheritdoc} */ public function key() { return $this->currentDate->getTimestamp(); } /** {@inheritdoc} */ public function valid() { return $this->currentDate->getTimestamp() <= $this->endDate->getTimestamp(); } /** {@inheritdoc} */ public function rewind() { $this->currentDate = clone $this->startDate; } } $workLoad = new PeriodIterator(new \DateTime('sunday last week'), new DateTime('last day of this month'), "1 day" ); $secondPeriod = $workLoad->current($workLoad); echo $secondPeriod->format('Y-m-d H:i:s');
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of PeriodIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/YvOku on line 53 Deprecated: Return type of PeriodIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/YvOku on line 59 Deprecated: Return type of PeriodIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/YvOku on line 65 Deprecated: Return type of PeriodIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/YvOku on line 71 Deprecated: Return type of PeriodIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/YvOku on line 77 Fatal error: Uncaught Error: Call to a member function format() on null in /in/YvOku:86 Stack trace: #0 {main} thrown in /in/YvOku on line 86
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
57.35 ms | 402 KiB | 8 Q