3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SwitchStage{ function __construct( public array $branches = [], public ?int $default = null ) {} function branch(int $case, int $then) { $this->branches[] = (object) ['case' => $case, 'then' => $then]; return $this; } function default(int $default) { $this->default = $default; return $this; } } $x = (new SwitchStage()) ->branch(case: 1, then: 2) ->branch(case: 3, then: 4) ->default(5); var_dump($x); $x = new SwitchStage([ ['case' => 1, 'then' => 2], ['case' => 3, 'then' => 4], ], default: 5); var_dump($x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nMO3p
function name:  (null)
number of ops:  29
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $1      'SwitchStage'
          1        DO_FCALL                                      0          
   19     2        INIT_METHOD_CALL                                         $1, 'branch'
          3        SEND_VAL_EX                                              1, 'case'
          4        SEND_VAL_EX                                              2, 'then'
          5        CHECK_UNDEF_ARGS                                         
          6        DO_FCALL                                      1  $3      
   20     7        INIT_METHOD_CALL                                         $3, 'branch'
          8        SEND_VAL_EX                                              3, 'case'
          9        SEND_VAL_EX                                              4, 'then'
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      1  $4      
   21    12        INIT_METHOD_CALL                                         $4, 'default'
         13        SEND_VAL_EX                                              5
         14        DO_FCALL                                      0  $5      
   18    15        ASSIGN                                                   !0, $5
   23    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
   25    19        NEW                                              $8      'SwitchStage'
   26    20        SEND_VAL_EX                                              <array>
   28    21        SEND_VAL_EX                                              5, 'default'
         22        CHECK_UNDEF_ARGS                                         
   25    23        DO_FCALL                                      1          
         24        ASSIGN                                                   !0, $8
   30    25        INIT_FCALL                                               'var_dump'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Class SwitchStage:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nMO3p
function name:  __construct
number of ops:  7
compiled vars:  !0 = $branches, !1 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV_INIT                                        !0      <array>
          1        RECV_INIT                                        !1      null
          2        ASSIGN_OBJ                                               'branches'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'default'
          5        OP_DATA                                                  !1
    7     6      > RETURN                                                   null

End of function __construct

Function branch:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nMO3p
function name:  branch
number of ops:  11
compiled vars:  !0 = $case, !1 = $then
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_ARRAY                                       ~4      !0, 'case'
          3        ADD_ARRAY_ELEMENT                                ~4      !1, 'then'
          4        CAST                                          8  ~5      ~4
          5        FETCH_OBJ_W                                      $2      'branches'
          6        ASSIGN_DIM                                               $2
          7        OP_DATA                                                  ~5
   10     8        FETCH_THIS                                       ~6      
          9      > RETURN                                                   ~6
   11    10*     > RETURN                                                   null

End of function branch

Function default:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nMO3p
function name:  default
number of ops:  6
compiled vars:  !0 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'default'
          2        OP_DATA                                                  !0
   14     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   15     5*     > RETURN                                                   null

End of function default

End of class SwitchStage.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.75 ms | 1005 KiB | 14 Q