3v4l.org

run code in 300+ PHP versions simultaneously
<?php $initialDate = DateTime::createFromFormat('U', '1409611999'); $initialDate = new DateTimeExtended($initialDate); $firstDayofWeek = clone $initialDate; $lastDayofWeek = clone $initialDate; $firstDayofWeek->setDayOfWeek('Monday', DateTimeExtended::WEEK_CURRENT); $lastDayofWeek->setDayOfWeek('Sunday', DateTimeExtended::WEEK_CURRENT); var_dump($firstDayofWeek, $lastDayofWeek); class DateTimeExtended Extends DateTime { const WEEK_CURRENT = 0; const WEEK_NEXT = 1; const WEEK_PREVIOUS = 2; protected static $days_of_week = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', ); public function __construct() { $args = func_get_args(); if (empty($args)) { throw new Exception('No argument supplied!'); } if ($args[0] instanceof DateTime) { parent::__construct($args[0]->format('Y-m-d H:i:s'), $args[0]->getTimezone()); } else { parent::__construct($args[0], isset($arg[1]) ? $arg[1] : null); } } public function setDayOfWeek($day, $margin = 0) { $day = strtolower($day); if (!is_int($day)) { $day = array_search($day, static::$days_of_week); } $current_day = $this->format('w'); switch($margin) { case static::WEEK_CURRENT: $interval = $day - $current_day; break; case static::WEEK_NEXT: $interval = 1; while($interval <= 7) { $current_day = ($current_day + 1) % 7; if ($current_day == $day) { break; } $interval++; } break; case static::WEEK_PREVIOUS: $interval = -1; while($interval >= -7) { $current_day -= 1; if ($current_day < 0) { $current_day = 6; } if ($current_day == $day) { break; } $interval--; } break; default: throw new Exception('Invalid margin supplied!'); } $i = abs($interval); $days = new DateInterval("P{$i}D"); if ($interval < 0) { $this->sub($days); } else { $this->add($days); } return $this; } }
Output for git.master, git.master_jit, rfc.property-hooks
object(DateTimeExtended)#1 (3) { ["date"]=> string(26) "2014-09-01 22:53:19.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeExtended)#3 (3) { ["date"]=> string(26) "2014-08-31 22:53:19.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" }

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:
46.08 ms | 401 KiB | 8 Q