3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { const PER_MONTH = 200000; /** * Get the number of working days in the current month. * * @return int */ private function getWorkingDaysThisMonth() { $working_days = 0; for ($i = 1; $i < date('t') + 1; $i++) { $thisDay = date('D', strtotime(date('Y-m-' . $i))); if (!($thisDay == 'Sun' || $thisDay == 'Sat')) { $working_days++; } } return $working_days; } /** * Get the number of records added to the site per second. * * @return float */ private function getRecordsPerSecond() { // Get the number of seconds in the current month // 9 is the number of working hours in one day (0830-1730). $seconds_current_month = $this->getWorkingDaysThisMonth() * 9 * 60 * 60; // Get the number of records per second $records_per_second = round(self::PER_MONTH / $seconds_current_month, 4); return $records_per_second; } /** * Get the number of rates added to the site to date. * * @param int $records_per_second The rate of records generated per second. * @return float|int */ private function getRatesToDate($records_per_second) { // Get the UNIX timestamp of the start of 2012-05-01 $start_month = strtotime('2012-05-01 00:00:00'); // Get the UNIX timestamp of the start of this month $start_of_current_month = strtotime(date('Y-m-01 00:00:00', time())); // First of current month // Set how many rates per month $counter = 0; // Work out where we are upto already while($start_month < $start_of_current_month) { // Add on historical months of rates $counter += self::PER_MONTH; $start_month = strtotime("+1 month", $start_month); } // Get the number of seconds that have passed in this month $seconds_elapsed_this_month = time() - $start_of_current_month; // Add on the remained of this month $counter += ceil($seconds_elapsed_this_month * $records_per_second); return $counter; } public function get() { $s = $this->getRecordsPerSecond(); return array( 'per_second' => $s, 'counter' => $this->getRatesToDate($s) ); } } $f = new Foo; var_dump($f->get());
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(2) { ["per_second"]=> float(0.3086) ["counter"]=> float(4931629) }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Nk5kA on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Nk5kA on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/Nk5kA on line 4
Process exited with code 255.