3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $dataFormat = array( "dateTimeOfData" => "DateTime", "open" => "double", "high" => "double", "low" => "double", "close" => "double", "volume" => "integer", "isCritical" => "boolean"//Temporary ); function validateFormat($data){ global $dataFormat; //Check that all the required fields exist $missing = array_diff_key($dataFormat, $data); $extra = array_diff_key($data, $dataFormat); if(!empty($missing) || !empty($extra)){ throw new InvalidArgumentException("Incorrect data format provided"); } //Check that all the data is of the correct type foreach($data as $k => $v){ $type = gettype($v) === "object" ? get_class($v) : gettype($v); $correctType = $dataFormat[$k]; if($type !== $correctType){ throw new InvalidArgumentException("Data is of an incorrect type."); } } } $arr = array("dateTimeOfData" => new DateTime(), //"open" => 10.1, "high" => 10.1, "low" => 10.1, "close" => 10.1, "volume" => 10, "isCritical" => true); validateFormat($arr);
based on nKjTu
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught InvalidArgumentException: Incorrect data format provided in /in/Umaef:19 Stack trace: #0 /in/Umaef(37): validateFormat(Array) #1 {main} thrown in /in/Umaef on line 19
Process exited with code 255.
Output for 5.3.17 - 5.6.21
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Incorrect data format provided' in /in/Umaef:19 Stack trace: #0 /in/Umaef(37): validateFormat(Array) #1 {main} thrown in /in/Umaef on line 19
Process exited with code 255.