3v4l.org

run code in 300+ PHP versions simultaneously
<?php $convertQ = function ($str) { switch ($str) { case '0': case 'No': return 'no'; case '1': case 'Yes': return 'yes'; case 'Unsure': return 'maybe'; default: throw new \InvalidArgumentException('Unaccounted for value for questionnaire field: ' . $str); } }; var_dump($convertQ(0)); // expect 'no', get 'no' var_dump($convertQ('No')); // expect 'no', get 'no' var_dump($convertQ(1)); // expect 'yes', get 'yes' var_dump($convertQ('Yes')); // expect 'yes', get 'yes' var_dump($convertQ('Unsure')); // expect 'maybe', get 'maybe' var_dump($convertQ('a')); // expect thrown error, get error thrown
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y8kdD
function name:  (null)
number of ops:  39
compiled vars:  !0 = $convertQ
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        ASSIGN                                                   !0, ~1
   21     2        INIT_FCALL                                               'var_dump'
          3        INIT_DYNAMIC_CALL                                        !0
          4        SEND_VAL_EX                                              0
          5        DO_FCALL                                      0  $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                                 
   22     8        INIT_FCALL                                               'var_dump'
          9        INIT_DYNAMIC_CALL                                        !0
         10        SEND_VAL_EX                                              'No'
         11        DO_FCALL                                      0  $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                                 
   23    14        INIT_FCALL                                               'var_dump'
         15        INIT_DYNAMIC_CALL                                        !0
         16        SEND_VAL_EX                                              1
         17        DO_FCALL                                      0  $7      
         18        SEND_VAR                                                 $7
         19        DO_ICALL                                                 
   24    20        INIT_FCALL                                               'var_dump'
         21        INIT_DYNAMIC_CALL                                        !0
         22        SEND_VAL_EX                                              'Yes'
         23        DO_FCALL                                      0  $9      
         24        SEND_VAR                                                 $9
         25        DO_ICALL                                                 
   25    26        INIT_FCALL                                               'var_dump'
         27        INIT_DYNAMIC_CALL                                        !0
         28        SEND_VAL_EX                                              'Unsure'
         29        DO_FCALL                                      0  $11     
         30        SEND_VAR                                                 $11
         31        DO_ICALL                                                 
   26    32        INIT_FCALL                                               'var_dump'
         33        INIT_DYNAMIC_CALL                                        !0
         34        SEND_VAL_EX                                              'a'
         35        DO_FCALL                                      0  $13     
         36        SEND_VAR                                                 $13
         37        DO_ICALL                                                 
         38      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Y8kdD
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        IS_EQUAL                                                 !0, '0'
          2      > JMPNZ                                                    ~1, ->12
    6     3    >   IS_EQUAL                                                 !0, 'No'
          4      > JMPNZ                                                    ~1, ->12
    9     5    >   IS_EQUAL                                                 !0, '1'
          6      > JMPNZ                                                    ~1, ->13
   10     7    >   IS_EQUAL                                                 !0, 'Yes'
          8      > JMPNZ                                                    ~1, ->13
   13     9    >   IS_EQUAL                                                 !0, 'Unsure'
         10      > JMPNZ                                                    ~1, ->14
         11    > > JMP                                                      ->15
    7    12    > > RETURN                                                   'no'
   11    13    > > RETURN                                                   'yes'
   14    14    > > RETURN                                                   'maybe'
   17    15    >   NEW                                              $2      'InvalidArgumentException'
         16        CONCAT                                           ~3      'Unaccounted+for+value+for+questionnaire+field%3A+', !0
         17        SEND_VAL_EX                                              ~3
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $2
   19    20*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.04 ms | 1456 KiB | 14 Q