3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if(!function_exists('cal_days_in_month')) { function cal_days_in_month($calendar, $month, $year) { return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); } if (!defined('CAL_GREGORIAN')) { define('CAL_GREGORIAN', 1); } } //tests echo '----- Basic Tests ----'; var_dump(cal_days_in_month(CAL_GREGORIAN, 1, 2014)); //31 var_dump(cal_days_in_month(CAL_GREGORIAN, 2, 2014)); //28 var_dump(cal_days_in_month(CAL_GREGORIAN, 10, 2014)); //31 var_dump(cal_days_in_month(CAL_GREGORIAN, 11, 2014)); //30 echo '----- Leap Years ----'; //some leap years - expect 29 for all var_dump(cal_days_in_month(CAL_GREGORIAN, 2, 1804)); var_dump(cal_days_in_month(CAL_GREGORIAN, 2, 2000)); var_dump(cal_days_in_month(CAL_GREGORIAN, 2, 2056)); var_dump(cal_days_in_month(CAL_GREGORIAN, 2, 1994)); echo '----- Invalid tests ----'; //some invalid ones: var_dump(cal_days_in_month(CAL_GREGORIAN, 1, 1)); var_dump(cal_days_in_month(CAL_GREGORIAN, 14, 2014)); //might be feb 2015? var_dump(cal_days_in_month(CAL_GREGORIAN, 1, 2014000)); //the far far future? var_dump(cal_days_in_month(CAL_GREGORIAN, 0, 2014)); //do we handle zero? var_dump(cal_days_in_month(CAL_GREGORIAN, -1, 2014)); //how about negative? var_dump(cal_days_in_month(CAL_GREGORIAN, 1, 0)); //and years? var_dump(cal_days_in_month(CAL_GREGORIAN, 1, -1)); //negative years?
based on ek0oZ
Output for 4.4.0 - 4.4.9, 5.0.5, 5.1.1 - 5.6.28, 7.0.0 - 7.1.0
----- Basic Tests ----int(31) int(28) int(31) int(30) ----- Leap Years ----int(29) int(29) int(29) int(28) ----- Invalid tests ----int(31) Warning: cal_days_in_month(): invalid date. in /in/fLm5U on line 32 bool(false) int(31) Warning: cal_days_in_month(): invalid date. in /in/fLm5U on line 34 bool(false) Warning: cal_days_in_month(): invalid date. in /in/fLm5U on line 35 bool(false) Warning: cal_days_in_month(): invalid date. in /in/fLm5U on line 36 bool(false) int(31)
Output for hhvm-3.10.0 - 3.12.0
----- Basic Tests ----int(31) int(28) int(31) int(30) ----- Leap Years ----int(29) int(29) int(29) int(28) ----- Invalid tests ----int(31) int(31) int(31) int(30) int(31) int(31) int(31)
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/fLm5U on line 37
Process exited with code 255.
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4
----- Basic Tests ----int(31) int(28) int(31) int(30) ----- Leap Years ----int(29) int(29) int(29) int(28) ----- Invalid tests ----int(31) int(2457024) int(31) int(2456659) int(2457024) int(1721426) int(31)