3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function despegar($endpoint, array $params = array()) { $url = sprintf( 'http://api.despegar.com/%s?%s', $endpoint, empty($params) ? null : http_build_query($params) ); $handle = curl_init($url); curl_setopt_array($handle, array( CURLOPT_ENCODING => 'gzip', CURLOPT_RETURNTRANSFER => true )); $response = curl_exec($handle); $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); if ( ! $response || 200 != $code) { throw new Exception( sprintf('(%d) Failed to obtain data from %s.', $code, $url), $code ); } return json_decode($response); } $cities = despegar('cities', array('pagesize' => 10)); if ($cities) { foreach ($cities->cities as $city) { printf("%s\n", $city->countryId); } }
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/UiYiO:10 Stack trace: #0 /in/UiYiO(30): despegar('cities', Array) #1 {main} thrown in /in/UiYiO on line 10
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Fatal error: Uncaught exception 'Exception' with message '(0) Failed to obtain data from http://api.despegar.com/cities?pagesize=10.' in /in/UiYiO:24 Stack trace: #0 /in/UiYiO(30): despegar() #1 {main}
Process exited with code 255.
Output for 5.1.0 - 5.6.28
Fatal error: Call to undefined function curl_init() in /in/UiYiO on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/UiYiO on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting '&' or T_VARIABLE or T_CONST in /in/UiYiO on line 2
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_ARRAY, expecting '&' or T_VARIABLE or T_CONST in /in/UiYiO on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'&'' or `T_VARIABLE' or `T_CONST' in /in/UiYiO on line 2
Process exited with code 255.