3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum Fruit { case APPLE; case ORANGE; case BANANA; } // Sample data foreach (["APPLE", "PEAR", "ORANGE", "LEMON", "BANANA", "STRAWBERRY"] as $fruit) { // Find matching fruit in all enum cases $fruits = Fruit::cases(); $matchingFruitIndex = array_search($fruit, array_column($fruits, "name")); // If found, eat it if ($matchingFruitIndex !== false) { $matchingFruit = $fruits[$matchingFruitIndex]; eatFruit($matchingFruit); } else { echo $fruit . " is not a valid Fruit\n"; } } function eatFruit(Fruit $fruit): void { if ($fruit === Fruit::APPLE) { echo "An apple a day keeps the doctor away\n"; } elseif ($fruit === Fruit::ORANGE) { echo "When life gives you oranges, make orange juice\n"; } elseif ($fruit === Fruit::BANANA) { echo "Banana for scale\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 26
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/ObD3s
function name:  (null)
number of ops:  28
compiled vars:  !0 = $fruit, !1 = $fruits, !2 = $matchingFruitIndex, !3 = $matchingFruit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'fruit'
   11     1      > FE_RESET_R                                       $4      <array>, ->26
          2    > > FE_FETCH_R                                               $4, !0, ->26
   13     3    >   INIT_STATIC_METHOD_CALL                                  'Fruit', 'cases'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !1, $5
   14     6        INIT_FCALL                                               'array_search'
          7        SEND_VAR                                                 !0
          8        INIT_FCALL                                               'array_column'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 'name'
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !2, $8
   17    15        TYPE_CHECK                                  1018          !2
         16      > JMPZ                                                     ~10, ->23
   18    17    >   FETCH_DIM_R                                      ~11     !1, !2
         18        ASSIGN                                                   !3, ~11
   19    19        INIT_FCALL_BY_NAME                                       'eatFruit'
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0          
   17    22      > JMP                                                      ->25
   21    23    >   CONCAT                                           ~14     !0, '+is+not+a+valid+Fruit%0A'
         24        ECHO                                                     ~14
   11    25    > > JMP                                                      ->2
         26    >   FE_FREE                                                  $4
   33    27      > RETURN                                                   1

Function eatfruit:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/ObD3s
function name:  eatFruit
number of ops:  16
compiled vars:  !0 = $fruit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        FETCH_CLASS_CONSTANT                             ~1      'Fruit', 'APPLE'
          2        IS_IDENTICAL                                             !0, ~1
          3      > JMPZ                                                     ~2, ->6
   27     4    >   ECHO                                                     'An+apple+a+day+keeps+the+doctor+away%0A'
   26     5      > JMP                                                      ->15
   28     6    >   FETCH_CLASS_CONSTANT                             ~3      'Fruit', 'ORANGE'
          7        IS_IDENTICAL                                             !0, ~3
          8      > JMPZ                                                     ~4, ->11
   29     9    >   ECHO                                                     'When+life+gives+you+oranges%2C+make+orange+juice%0A'
   28    10      > JMP                                                      ->15
   30    11    >   FETCH_CLASS_CONSTANT                             ~5      'Fruit', 'BANANA'
         12        IS_IDENTICAL                                             !0, ~5
         13      > JMPZ                                                     ~6, ->15
   31    14    >   ECHO                                                     'Banana+for+scale%0A'
   33    15    > > RETURN                                                   null

End of function eatfruit

Class Fruit: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.14 ms | 1438 KiB | 15 Q