3v4l.org

run code in 300+ PHP versions simultaneously
<?php function validateFormat($data){ //Check that all the required fields exist $missing = array_diff_key(self::$dataFormat, $data); $extra = array_diff_key($data, self::$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 = self::$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);
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.29, 5.6.7 - 5.6.13
Fatal error: Cannot access self:: when no class scope is active in /in/i4dNL on line 4
Process exited with code 255.

preferences:
190.55 ms | 1395 KiB | 63 Q