3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * ageCheck method * * This is a custom validation method that converts the date of birth into an age and then checks to see if the age falls within the teams level age range * * @param array $check This is the value for date of birth field * @param string $level_id This is the level_id selected for this competitor's team * @return bool */ function ageCheck($check, $level_id) { $dob = array_shift($check); $dob = new DateTime($dob); $today = new DateTime('today'); $age = $dob->diff($today)->y; $age_range = 'n/a-n/a'; $age_range_arr = explode('-', $age_range); if (stripos($age_range,'N/A') !== false) { return true; } if ($age >= $age_range_arr[0] && $age <= $age_range_arr[1]) { return true; } return 'You must select a date of birth where the competitor\'s age is between' . $age_range_arr[0] . '-' . $age_range_arr[1]; } echo ageCheck(array('dob' => '1978-11-21'), NULL);
Output for 5.3.0 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
1
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::diff() in /in/FLBZc on line 17
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/FLBZc on line 15
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/FLBZc on line 17
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_OBJECT_OPERATOR in /in/FLBZc on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/FLBZc on line 17
Process exited with code 255.