3v4l.org

run code in 300+ PHP versions simultaneously
<?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); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 16
filename:       /in/UiYiO
function name:  (null)
number of ops:  17
compiled vars:  !0 = $cities, !1 = $city
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'despegar'
          1        SEND_VAL                                                 'cities'
          2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   32     5      > JMPZ                                                     !0, ->16
   33     6    >   FETCH_OBJ_R                                      ~4      !0, 'cities'
          7      > FE_RESET_R                                       $5      ~4, ->15
          8    > > FE_FETCH_R                                               $5, !1, ->15
   34     9    >   INIT_FCALL                                               'printf'
         10        SEND_VAL                                                 '%25s%0A'
         11        FETCH_OBJ_R                                      ~6      !1, 'countryId'
         12        SEND_VAL                                                 ~6
         13        DO_ICALL                                                 
   33    14      > JMP                                                      ->8
         15    >   FE_FREE                                                  $5
   36    16    > > RETURN                                                   1

Function despegar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 47) Position 1 = 40, Position 2 = 42
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 53
Branch analysis from position: 43
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 40, Position 2 = 42
Branch analysis from position: 40
Branch analysis from position: 42
filename:       /in/UiYiO
function name:  despegar
number of ops:  58
compiled vars:  !0 = $endpoint, !1 = $params, !2 = $url, !3 = $handle, !4 = $response, !5 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    4     2        INIT_FCALL                                               'sprintf'
    5     3        SEND_VAL                                                 'http%3A%2F%2Fapi.despegar.com%2F%25s%3F%25s'
    6     4        SEND_VAR                                                 !0
    7     5        ISSET_ISEMPTY_CV                                         !1
          6      > JMPZ                                                     ~6, ->9
          7    >   QM_ASSIGN                                        ~7      null
          8      > JMP                                                      ->13
          9    >   INIT_FCALL                                               'http_build_query'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $8      
         12        QM_ASSIGN                                        ~7      $8
         13    >   SEND_VAL                                                 ~7
         14        DO_ICALL                                         $9      
    4    15        ASSIGN                                                   !2, $9
   10    16        INIT_FCALL_BY_NAME                                       'curl_init'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !3, $11
   12    20        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
         21        SEND_VAR_EX                                              !3
   13    22        FETCH_CONSTANT                                   ~13     'CURLOPT_ENCODING'
         23        INIT_ARRAY                                       ~14     'gzip', ~13
   14    24        FETCH_CONSTANT                                   ~15     'CURLOPT_RETURNTRANSFER'
   13    25        ADD_ARRAY_ELEMENT                                ~14     <true>, ~15
         26        SEND_VAL_EX                                              ~14
         27        DO_FCALL                                      0          
   17    28        INIT_FCALL_BY_NAME                                       'curl_exec'
         29        SEND_VAR_EX                                              !3
         30        DO_FCALL                                      0  $17     
         31        ASSIGN                                                   !4, $17
   18    32        INIT_FCALL_BY_NAME                                       'curl_getinfo'
         33        SEND_VAR_EX                                              !3
         34        FETCH_CONSTANT                                   ~19     'CURLINFO_HTTP_CODE'
         35        SEND_VAL_EX                                              ~19
         36        DO_FCALL                                      0  $20     
         37        ASSIGN                                                   !5, $20
   20    38        BOOL_NOT                                         ~22     !4
         39      > JMPNZ_EX                                         ~22     ~22, ->42
         40    >   IS_NOT_EQUAL                                     ~23     !5, 200
         41        BOOL                                             ~22     ~23
         42    > > JMPZ                                                     ~22, ->53
   21    43    >   NEW                                              $24     'Exception'
   22    44        INIT_FCALL                                               'sprintf'
         45        SEND_VAL                                                 '%28%25d%29+Failed+to+obtain+data+from+%25s.'
         46        SEND_VAR                                                 !5
         47        SEND_VAR                                                 !2
         48        DO_ICALL                                         $25     
         49        SEND_VAR_NO_REF_EX                                       $25
         50        SEND_VAR_EX                                              !5
         51        DO_FCALL                                      0          
         52      > THROW                                         0          $24
   27    53    >   INIT_FCALL                                               'json_decode'
         54        SEND_VAR                                                 !4
         55        DO_ICALL                                         $27     
         56      > RETURN                                                   $27
   28    57*     > RETURN                                                   null

End of function despegar

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184 ms | 1411 KiB | 22 Q