3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PayDay { public function __construct($dmY = null) { $this->date = (is_null($dmY) ? new DateTime("midnight") : DateTime::createFromFormat('!d/m/Y', $dmY)); // ! for midnight $holiday_calendar = [ // import this data however you wish (object)["holiday" => "New Year's Day", "holidayDate" => "2018-01-01"], (object)["holiday" => "Republic Day", "holidayDate" => "2018-01-26"], (object)["holiday" => "Holi", "holidayDate" => "2018-03-02"] ]; $this->blacklist_holidates = []; if (!empty($holiday_calendar)) { foreach ($holiday_calendar as $obj) { $this->blacklist_holidates[$obj->holiday] = DateTime::createFromFormat('!Y-m-d', $obj->holidayDate); // ! for midnight } } $payroll_days_list = [ // import this data however you wish (object)["payrollDay" => "Mon", "isPayrollDay" => "Y"], (object)["payrollDay" => "Tue", "isPayrollDay" => "Y"], (object)["payrollDay" => "Wed", "isPayrollDay" => "Y"], (object)["payrollDay" => "Thu", "isPayrollDay" => "Y"], (object)["payrollDay" => "Fri", "isPayrollDay" => "Y"], (object)["payrollDay" => "Sat", "isPayrollDay" => "N"], (object)["payrollDay" => "Sun", "isPayrollDay" => "N"] ]; $this->blacklist_daynames = []; if (!empty($payroll_days_list)) { foreach ($payroll_days_list as $obj) { if ($obj->isPayrollDay == "N") { $this->blacklist_daynames[] = $obj->payrollDay; } } } } public function getPayDate() { while (in_array($this->date, $this->blacklist_holidates) || in_array($this->date->format("D"), $this->blacklist_daynames)) { $this->date->sub(new DateInterval('P1D')); } return $this->date->format("d/m/Y"); } } $input = "04/03/2018"; echo "Starting Date: $input\n"; $date = new PayDay($input); echo "Qualifying PayDate: ",$date->getPayDate();
Output for git.master, git.master_jit, rfc.property-hooks
Starting Date: 04/03/2018 Deprecated: Creation of dynamic property PayDay::$date is deprecated in /in/UMUY7 on line 5 Deprecated: Creation of dynamic property PayDay::$blacklist_holidates is deprecated in /in/UMUY7 on line 12 Deprecated: Creation of dynamic property PayDay::$blacklist_daynames is deprecated in /in/UMUY7 on line 28 Qualifying PayDate: 01/03/2018

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:
197.61 ms | 406 KiB | 5 Q