3v4l.org

run code in 300+ PHP versions simultaneously
<?php // simulate network latency in seconds $seconds = 0.2; usleep($seconds * 1000000); function randomAverageSpeed() { return rand(5, 15); } class Runner { public $age, $distance, $time, $averageSpeed, $distanceKind; public function __construct($age, $distance, $time, $averageSpeed) { $this->age = $age; $this->distance = $distance; $this->time = $time; $this->averageSpeed = $averageSpeed; $this->distanceKind = $this->distanceKindConverter($distance); } private function distanceKindConverter($distanceAmount) { $distances = array( 5 => '', 10 => 'long', 7.195 => 'medium' ); return $distances[$distanceAmount]; } } $team1 = array( 'Piet' => new Runner(39, 5, 0, randomAverageSpeed()), 'Ellen' => new Runner(19, 10, 0, randomAverageSpeed()), 'Jan' => new Runner(32, 5, 0, randomAverageSpeed()), 'Petra' => new Runner(27, 10, 0, randomAverageSpeed()), 'Kees' => new Runner(15, 5, 0, randomAverageSpeed()), 'Kate' => new Runner(18, 7.195, 0, randomAverageSpeed()) ); $team2 = array( 'Klaas' => new Runner(46, 5, 0, randomAverageSpeed()), 'Beatrix' => new Runner(52, 10, 0, randomAverageSpeed()), 'Willem' => new Runner(34, 5, 0, randomAverageSpeed()), 'Alexander' => new Runner(30, 10, 0, randomAverageSpeed()), 'Maxima' => new Runner(44, 5, 0, randomAverageSpeed()), 'Amalia' => new Runner(26, 7.195, 0, randomAverageSpeed()) ); $team3 = array( 'Huub' => new Runner(55, 5, 0, randomAverageSpeed()), 'Nelly' => new Runner(50, 10, 0, randomAverageSpeed()), 'Rene' => new Runner(43, 5, 0, randomAverageSpeed()), 'Tatjana' => new Runner(45, 10, 0, randomAverageSpeed()), 'Boris' => new Runner(28, 5, 0, randomAverageSpeed()), 'Wodan' => new Runner(23, 7.195, 0, randomAverageSpeed()) ); $teams = [ 'Team 1' => $team1, 'Team 2' => $team2, 'Team 3' => $team3, ]; if (isset($_GET['getAllTeamData'])) { echo json_encode($teams); } if (isset($_GET['getLatestTeamDistanceData'])) { $teamsStats = [ 'Team 1' => rand(0, 1), 'Team 2' => rand(0, 1), 'Team 3' => rand(0, 1), ]; echo json_encode($teamsStats); } if (isset($_GET['getRunnerInfo'])) { $searchRunnerValue = trim($_GET['getRunnerInfo']); foreach ($teams as $key => $value) { foreach ($teams[$key] as $runner => $data) { if ($searchRunnerValue === $runner) { // remove some data unset($teams[$key][$runner]->distanceKind); unset($teams[$key][$runner]->time); unset($teams[$key][$runner]->averageSpeed); echo json_encode($teams[$key][$runner]); return; } } } if ($searchRunnerValue !== '') { echo 'ERROR: runner <strong>' . $searchRunnerValue . '</strong> not found!'; } else { echo 'ERROR: no runner name given!'; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 177, Position 2 = 181
Branch analysis from position: 177
2 jumps found. (Code = 43) Position 1 = 184, Position 2 = 204
Branch analysis from position: 184
2 jumps found. (Code = 43) Position 1 = 207, Position 2 = 251
Branch analysis from position: 207
2 jumps found. (Code = 77) Position 1 = 214, Position 2 = 243
Branch analysis from position: 214
2 jumps found. (Code = 78) Position 1 = 215, Position 2 = 243
Branch analysis from position: 215
2 jumps found. (Code = 77) Position 1 = 218, Position 2 = 241
Branch analysis from position: 218
2 jumps found. (Code = 78) Position 1 = 219, Position 2 = 241
Branch analysis from position: 219
2 jumps found. (Code = 43) Position 1 = 222, Position 2 = 240
Branch analysis from position: 222
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 240
1 jumps found. (Code = 42) Position 1 = 218
Branch analysis from position: 218
Branch analysis from position: 241
1 jumps found. (Code = 42) Position 1 = 214
Branch analysis from position: 214
Branch analysis from position: 241
Branch analysis from position: 243
2 jumps found. (Code = 43) Position 1 = 246, Position 2 = 250
Branch analysis from position: 246
1 jumps found. (Code = 42) Position 1 = 251
Branch analysis from position: 251
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 250
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 243
Branch analysis from position: 251
Branch analysis from position: 204
Branch analysis from position: 181
filename:       /in/eOXbQ
function name:  (null)
number of ops:  252
compiled vars:  !0 = $seconds, !1 = $team1, !2 = $team2, !3 = $team3, !4 = $teams, !5 = $teamsStats, !6 = $searchRunnerValue, !7 = $value, !8 = $key, !9 = $data, !10 = $runner
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 0.2
    5     1        INIT_FCALL                                               'usleep'
          2        MUL                                              ~12     !0, 1000000
          3        SEND_VAL                                                 ~12
          4        DO_ICALL                                                 
   38     5        NEW                                              $14     'Runner'
          6        SEND_VAL_EX                                              39
          7        SEND_VAL_EX                                              5
          8        SEND_VAL_EX                                              0
          9        INIT_FCALL                                               'randomaveragespeed'
         10        DO_FCALL                                      0  $15     
         11        SEND_VAR_NO_REF_EX                                       $15
         12        DO_FCALL                                      0          
         13        INIT_ARRAY                                       ~17     $14, 'Piet'
   39    14        NEW                                              $18     'Runner'
         15        SEND_VAL_EX                                              19
         16        SEND_VAL_EX                                              10
         17        SEND_VAL_EX                                              0
         18        INIT_FCALL                                               'randomaveragespeed'
         19        DO_FCALL                                      0  $19     
         20        SEND_VAR_NO_REF_EX                                       $19
         21        DO_FCALL                                      0          
         22        ADD_ARRAY_ELEMENT                                ~17     $18, 'Ellen'
   40    23        NEW                                              $21     'Runner'
         24        SEND_VAL_EX                                              32
         25        SEND_VAL_EX                                              5
         26        SEND_VAL_EX                                              0
         27        INIT_FCALL                                               'randomaveragespeed'
         28        DO_FCALL                                      0  $22     
         29        SEND_VAR_NO_REF_EX                                       $22
         30        DO_FCALL                                      0          
         31        ADD_ARRAY_ELEMENT                                ~17     $21, 'Jan'
   41    32        NEW                                              $24     'Runner'
         33        SEND_VAL_EX                                              27
         34        SEND_VAL_EX                                              10
         35        SEND_VAL_EX                                              0
         36        INIT_FCALL                                               'randomaveragespeed'
         37        DO_FCALL                                      0  $25     
         38        SEND_VAR_NO_REF_EX                                       $25
         39        DO_FCALL                                      0          
         40        ADD_ARRAY_ELEMENT                                ~17     $24, 'Petra'
   42    41        NEW                                              $27     'Runner'
         42        SEND_VAL_EX                                              15
         43        SEND_VAL_EX                                              5
         44        SEND_VAL_EX                                              0
         45        INIT_FCALL                                               'randomaveragespeed'
         46        DO_FCALL                                      0  $28     
         47        SEND_VAR_NO_REF_EX                                       $28
         48        DO_FCALL                                      0          
         49        ADD_ARRAY_ELEMENT                                ~17     $27, 'Kees'
   43    50        NEW                                              $30     'Runner'
         51        SEND_VAL_EX                                              18
         52        SEND_VAL_EX                                              7.195
         53        SEND_VAL_EX                                              0
         54        INIT_FCALL                                               'randomaveragespeed'
         55        DO_FCALL                                      0  $31     
         56        SEND_VAR_NO_REF_EX                                       $31
         57        DO_FCALL                                      0          
         58        ADD_ARRAY_ELEMENT                                ~17     $30, 'Kate'
   37    59        ASSIGN                                                   !1, ~17
   47    60        NEW                                              $34     'Runner'
         61        SEND_VAL_EX                                              46
         62        SEND_VAL_EX                                              5
         63        SEND_VAL_EX                                              0
         64        INIT_FCALL                                               'randomaveragespeed'
         65        DO_FCALL                                      0  $35     
         66        SEND_VAR_NO_REF_EX                                       $35
         67        DO_FCALL                                      0          
         68        INIT_ARRAY                                       ~37     $34, 'Klaas'
   48    69        NEW                                              $38     'Runner'
         70        SEND_VAL_EX                                              52
         71        SEND_VAL_EX                                              10
         72        SEND_VAL_EX                                              0
         73        INIT_FCALL                                               'randomaveragespeed'
         74        DO_FCALL                                      0  $39     
         75        SEND_VAR_NO_REF_EX                                       $39
         76        DO_FCALL                                      0          
         77        ADD_ARRAY_ELEMENT                                ~37     $38, 'Beatrix'
   49    78        NEW                                              $41     'Runner'
         79        SEND_VAL_EX                                              34
         80        SEND_VAL_EX                                              5
         81        SEND_VAL_EX                                              0
         82        INIT_FCALL                                               'randomaveragespeed'
         83        DO_FCALL                                      0  $42     
         84        SEND_VAR_NO_REF_EX                                       $42
         85        DO_FCALL                                      0          
         86        ADD_ARRAY_ELEMENT                                ~37     $41, 'Willem'
   50    87        NEW                                              $44     'Runner'
         88        SEND_VAL_EX                                              30
         89        SEND_VAL_EX                                              10
         90        SEND_VAL_EX                                              0
         91        INIT_FCALL                                               'randomaveragespeed'
         92        DO_FCALL                                      0  $45     
         93        SEND_VAR_NO_REF_EX                                       $45
         94        DO_FCALL                                      0          
         95        ADD_ARRAY_ELEMENT                                ~37     $44, 'Alexander'
   51    96        NEW                                              $47     'Runner'
         97        SEND_VAL_EX                                              44
         98        SEND_VAL_EX                                              5
         99        SEND_VAL_EX                                              0
        100        INIT_FCALL                                               'randomaveragespeed'
        101        DO_FCALL                                      0  $48     
        102        SEND_VAR_NO_REF_EX                                       $48
        103        DO_FCALL                                      0          
        104        ADD_ARRAY_ELEMENT                                ~37     $47, 'Maxima'
   52   105        NEW                                              $50     'Runner'
        106        SEND_VAL_EX                                              26
        107        SEND_VAL_EX                                              7.195
        108        SEND_VAL_EX                                              0
        109        INIT_FCALL                                               'randomaveragespeed'
        110        DO_FCALL                                      0  $51     
        111        SEND_VAR_NO_REF_EX                                       $51
        112        DO_FCALL                                      0          
        113        ADD_ARRAY_ELEMENT                                ~37     $50, 'Amalia'
   46   114        ASSIGN                                                   !2, ~37
   56   115        NEW                                              $54     'Runner'
        116        SEND_VAL_EX                                              55
        117        SEND_VAL_EX                                              5
        118        SEND_VAL_EX                                              0
        119        INIT_FCALL                                               'randomaveragespeed'
        120        DO_FCALL                                      0  $55     
        121        SEND_VAR_NO_REF_EX                                       $55
        122        DO_FCALL                                      0          
        123        INIT_ARRAY                                       ~57     $54, 'Huub'
   57   124        NEW                                              $58     'Runner'
        125        SEND_VAL_EX                                              50
        126        SEND_VAL_EX                                              10
        127        SEND_VAL_EX                                              0
        128        INIT_FCALL                                               'randomaveragespeed'
        129        DO_FCALL                                      0  $59     
        130        SEND_VAR_NO_REF_EX                                       $59
        131        DO_FCALL                                      0          
        132        ADD_ARRAY_ELEMENT                                ~57     $58, 'Nelly'
   58   133        NEW                                              $61     'Runner'
        134        SEND_VAL_EX                                              43
        135        SEND_VAL_EX                                              5
        136        SEND_VAL_EX                                              0
        137        INIT_FCALL                                               'randomaveragespeed'
        138        DO_FCALL                                      0  $62     
        139        SEND_VAR_NO_REF_EX                                       $62
        140        DO_FCALL                                      0          
        141        ADD_ARRAY_ELEMENT                                ~57     $61, 'Rene'
   59   142        NEW                                              $64     'Runner'
        143        SEND_VAL_EX                                              45
        144        SEND_VAL_EX                                              10
        145        SEND_VAL_EX                                              0
        146        INIT_FCALL                                               'randomaveragespeed'
        147        DO_FCALL                                      0  $65     
        148        SEND_VAR_NO_REF_EX                                       $65
        149        DO_FCALL                                      0          
        150        ADD_ARRAY_ELEMENT                                ~57     $64, 'Tatjana'
   60   151        NEW                                              $67     'Runner'
        152        SEND_VAL_EX                                              28
        153        SEND_VAL_EX                                              5
        154        SEND_VAL_EX                                              0
        155        INIT_FCALL                                               'randomaveragespeed'
        156        DO_FCALL                                      0  $68     
        157        SEND_VAR_NO_REF_EX                                       $68
        158        DO_FCALL                                      0          
        159        ADD_ARRAY_ELEMENT                                ~57     $67, 'Boris'
   61   160        NEW                                              $70     'Runner'
        161        SEND_VAL_EX                                              23
        162        SEND_VAL_EX                                              7.195
        163        SEND_VAL_EX                                              0
        164        INIT_FCALL                                               'randomaveragespeed'
        165        DO_FCALL                                      0  $71     
        166        SEND_VAR_NO_REF_EX                                       $71
        167        DO_FCALL                                      0          
        168        ADD_ARRAY_ELEMENT                                ~57     $70, 'Wodan'
   55   169        ASSIGN                                                   !3, ~57
   65   170        INIT_ARRAY                                       ~74     !1, 'Team+1'
   66   171        ADD_ARRAY_ELEMENT                                ~74     !2, 'Team+2'
   67   172        ADD_ARRAY_ELEMENT                                ~74     !3, 'Team+3'
   64   173        ASSIGN                                                   !4, ~74
   70   174        FETCH_IS                                         ~76     '_GET'
        175        ISSET_ISEMPTY_DIM_OBJ                         0          ~76, 'getAllTeamData'
        176      > JMPZ                                                     ~77, ->181
   71   177    >   INIT_FCALL                                               'json_encode'
        178        SEND_VAR                                                 !4
        179        DO_ICALL                                         $78     
        180        ECHO                                                     $78
   73   181    >   FETCH_IS                                         ~79     '_GET'
        182        ISSET_ISEMPTY_DIM_OBJ                         0          ~79, 'getLatestTeamDistanceData'
        183      > JMPZ                                                     ~80, ->204
   75   184    >   INIT_FCALL                                               'rand'
        185        SEND_VAL                                                 0
        186        SEND_VAL                                                 1
        187        DO_ICALL                                         $81     
        188        INIT_ARRAY                                       ~82     $81, 'Team+1'
   76   189        INIT_FCALL                                               'rand'
        190        SEND_VAL                                                 0
        191        SEND_VAL                                                 1
        192        DO_ICALL                                         $83     
        193        ADD_ARRAY_ELEMENT                                ~82     $83, 'Team+2'
   77   194        INIT_FCALL                                               'rand'
        195        SEND_VAL                                                 0
        196        SEND_VAL                                                 1
        197        DO_ICALL                                         $84     
        198        ADD_ARRAY_ELEMENT                                ~82     $84, 'Team+3'
   74   199        ASSIGN                                                   !5, ~82
   79   200        INIT_FCALL                                               'json_encode'
        201        SEND_VAR                                                 !5
        202        DO_ICALL                                         $86     
        203        ECHO                                                     $86
   81   204    >   FETCH_IS                                         ~87     '_GET'
        205        ISSET_ISEMPTY_DIM_OBJ                         0          ~87, 'getRunnerInfo'
        206      > JMPZ                                                     ~88, ->251
   82   207    >   INIT_FCALL                                               'trim'
        208        FETCH_R                      global              ~89     '_GET'
        209        FETCH_DIM_R                                      ~90     ~89, 'getRunnerInfo'
        210        SEND_VAL                                                 ~90
        211        DO_ICALL                                         $91     
        212        ASSIGN                                                   !6, $91
   84   213      > FE_RESET_R                                       $93     !4, ->243
        214    > > FE_FETCH_R                                       ~94     $93, !7, ->243
        215    >   ASSIGN                                                   !8, ~94
   85   216        FETCH_DIM_R                                      ~96     !4, !8
        217      > FE_RESET_R                                       $97     ~96, ->241
        218    > > FE_FETCH_R                                       ~98     $97, !9, ->241
        219    >   ASSIGN                                                   !10, ~98
   86   220        IS_IDENTICAL                                             !6, !10
        221      > JMPZ                                                     ~100, ->240
   88   222    >   FETCH_DIM_UNSET                                  $101    !4, !8
        223        FETCH_DIM_UNSET                                  $102    $101, !10
        224        UNSET_OBJ                                                $102, 'distanceKind'
   89   225        FETCH_DIM_UNSET                                  $103    !4, !8
        226        FETCH_DIM_UNSET                                  $104    $103, !10
        227        UNSET_OBJ                                                $104, 'time'
   90   228        FETCH_DIM_UNSET                                  $105    !4, !8
        229        FETCH_DIM_UNSET                                  $106    $105, !10
        230        UNSET_OBJ                                                $106, 'averageSpeed'
   92   231        INIT_FCALL                                               'json_encode'
        232        FETCH_DIM_R                                      ~107    !4, !8
        233        FETCH_DIM_R                                      ~108    ~107, !10
        234        SEND_VAL                                                 ~108
        235        DO_ICALL                                         $109    
        236        ECHO                                                     $109
   93   237        FE_FREE                                                  $97
        238        FE_FREE                                                  $93
        239      > RETURN                                                   null
   85   240    > > JMP                                                      ->218
        241    >   FE_FREE                                                  $97
   84   242      > JMP                                                      ->214
        243    >   FE_FREE                                                  $93
   98   244        IS_NOT_IDENTICAL                                         !6, ''
        245      > JMPZ                                                     ~110, ->250
   99   246    >   CONCAT                                           ~111    'ERROR%3A+runner+%3Cstrong%3E', !6
        247        CONCAT                                           ~112    ~111, '%3C%2Fstrong%3E+not+found%21'
        248        ECHO                                                     ~112
        249      > JMP                                                      ->251
  101   250    >   ECHO                                                     'ERROR%3A+no+runner+name+given%21'
  103   251    > > RETURN                                                   1

Function randomaveragespeed:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eOXbQ
function name:  randomAverageSpeed
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 5
          2        SEND_VAL                                                 15
          3        DO_ICALL                                         $0      
          4      > RETURN                                                   $0
   10     5*     > RETURN                                                   null

End of function randomaveragespeed

Class Runner:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eOXbQ
function name:  __construct
number of ops:  18
compiled vars:  !0 = $age, !1 = $distance, !2 = $time, !3 = $averageSpeed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   19     4        ASSIGN_OBJ                                               'age'
          5        OP_DATA                                                  !0
   20     6        ASSIGN_OBJ                                               'distance'
          7        OP_DATA                                                  !1
   21     8        ASSIGN_OBJ                                               'time'
          9        OP_DATA                                                  !2
   22    10        ASSIGN_OBJ                                               'averageSpeed'
         11        OP_DATA                                                  !3
   23    12        INIT_METHOD_CALL                                         'distanceKindConverter'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $9      
         15        ASSIGN_OBJ                                               'distanceKind'
         16        OP_DATA                                                  $9
   24    17      > RETURN                                                   null

End of function __construct

Function distancekindconverter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eOXbQ
function name:  distanceKindConverter
number of ops:  5
compiled vars:  !0 = $distanceAmount, !1 = $distances
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN                                                   !1, <array>
   33     2        FETCH_DIM_R                                      ~3      !1, !0
          3      > RETURN                                                   ~3
   34     4*     > RETURN                                                   null

End of function distancekindconverter

End of class Runner.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.24 ms | 1414 KiB | 39 Q