3v4l.org

run code in 500+ PHP versions simultaneously
<?php function mysweetcode($argument){ $required=['first'];//specify required parameters here $default=['first'=>0,'second'=>1,'third'=>2];//define all parameters with their default values here $missing=[]; if(!is_array($argument)) return false; $argument=array_intersect_key($argument,$default); foreach($required as $k=>$v){//check for missing required parameters if(!isset($argument[$v])) $missing[]=$v; } if(!empty($missing)){// if required are missing trigger or throw error according to the PHP version $cm=count($missing); if (version_compare(PHP_VERSION, '7.0.0') < 0) { trigger_error(call_user_func_array('sprintf', array_merge(array('Required '.(($cm>1)?'parameters:':'parameter:'). str_repeat('%s,',$cm).(($cm>1)?' are':' is').' missing'),$missing)), E_USER_ERROR); }else{ throw new Error(call_user_func_array('sprintf',array_merge( array('Required '.(($cm>1)?'parameters:':'parameter:'). str_repeat('%s',$cm).(($cm>1)?' are':' is').' missing'),$missing))); } } $default=array_merge($default,$argument);//assign given values to parameters extract($default);/*extract the parameters to allow further checking and other operations in the function or method*/ unset($required,$missing,$argument,$default,$k,$v);//gain some space //then you can use $first,$second,$third in your code return $first+$second+$third; } var_dump(mysweetcode(['first'=>9,'third'=>8])); var_dump(mysweetcode(['third'=>8]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HZ58e
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'mysweetcode'
          2        SEND_VAL                                                     <array>
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
          5        DO_ICALL                                                     
   39     6        INIT_FCALL                                                   'var_dump'
          7        INIT_FCALL                                                   'mysweetcode'
          8        SEND_VAL                                                     <array>
          9        DO_FCALL                                          0  $2      
         10        SEND_VAR                                                     $2
         11        DO_ICALL                                                     
         12      > RETURN                                                       1

Function mysweetcode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 21
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 97
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 66
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 52
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 52
Branch analysis from position: 50
Branch analysis from position: 52
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 73
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 84
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
Branch analysis from position: 84
Branch analysis from position: 97
Branch analysis from position: 22
filename:       /in/HZ58e
function name:  mysweetcode
number of ops:  115
compiled vars:  !0 = $argument, !1 = $required, !2 = $default, !3 = $missing, !4 = $v, !5 = $k, !6 = $cm, !7 = $first, !8 = $second, !9 = $third
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        ASSIGN                                                       !1, <array>
    5     2        ASSIGN                                                       !2, <array>
    6     3        ASSIGN                                                       !3, <array>
    7     4        TYPE_CHECK                                      128  ~13     !0
          5        BOOL_NOT                                             ~14     ~13
          6      > JMPZ                                                         ~14, ->8
          7    > > RETURN                                                       <false>
    8     8    >   INIT_FCALL                                                   'array_intersect_key'
          9        SEND_VAR                                                     !0
         10        SEND_VAR                                                     !2
         11        DO_ICALL                                             $15     
         12        ASSIGN                                                       !0, $15
    9    13      > FE_RESET_R                                           $17     !1, ->22
         14    > > FE_FETCH_R                                           ~18     $17, !4, ->22
         15    >   ASSIGN                                                       !5, ~18
   10    16        ISSET_ISEMPTY_DIM_OBJ                             0  ~20     !0, !4
         17        BOOL_NOT                                             ~21     ~20
         18      > JMPZ                                                         ~21, ->21
   11    19    >   ASSIGN_DIM                                                   !3
         20        OP_DATA                                                      !4
    9    21    > > JMP                                                          ->14
         22    >   FE_FREE                                                      $17
   13    23        ISSET_ISEMPTY_CV                                     ~23     !3
         24        BOOL_NOT                                             ~24     ~23
         25      > JMPZ                                                         ~24, ->97
   14    26    >   COUNT                                                ~25     !3
         27        ASSIGN                                                       !6, ~25
   15    28        INIT_FCALL                                                   'version_compare'
         29        SEND_VAL                                                     '8.5.0'
         30        SEND_VAL                                                     '7.0.0'
         31        DO_ICALL                                             $27     
         32        IS_SMALLER                                                   $27, 0
         33      > JMPZ                                                         ~28, ->66
   16    34    >   INIT_FCALL                                                   'trigger_error'
         35        INIT_FCALL                                                   'sprintf'
   17    36        INIT_FCALL                                                   'array_merge'
         37        IS_SMALLER                                                   1, !6
         38      > JMPZ                                                         ~29, ->41
         39    >   QM_ASSIGN                                            ~30     'parameters%3A'
         40      > JMP                                                          ->42
         41    >   QM_ASSIGN                                            ~30     'parameter%3A'
         42    >   CONCAT                                               ~31     'Required+', ~30
   18    43        INIT_FCALL                                                   'str_repeat'
         44        SEND_VAL                                                     '%25s%2C'
         45        SEND_VAR                                                     !6
         46        DO_ICALL                                             $32     
         47        CONCAT                                               ~33     ~31, $32
         48        IS_SMALLER                                                   1, !6
         49      > JMPZ                                                         ~34, ->52
         50    >   QM_ASSIGN                                            ~35     '+are'
         51      > JMP                                                          ->53
         52    >   QM_ASSIGN                                            ~35     '+is'
         53    >   CONCAT                                               ~36     ~33, ~35
         54        CONCAT                                               ~37     ~36, '+missing'
         55        INIT_ARRAY                                           ~38     ~37
         56        SEND_VAL                                                     ~38
         57        SEND_VAR                                                     !3
   17    58        DO_ICALL                                             $39     
   18    59        SEND_ARRAY                                                   $39
         60        CHECK_UNDEF_ARGS                                             
         61        DO_FCALL                                          1  $40     
         62        SEND_VAR                                                     $40
   19    63        SEND_VAL                                                     256
   16    64        DO_ICALL                                                     
   15    65      > JMP                                                          ->97
   21    66    >   NEW                                                  $42     'Error'
         67        INIT_FCALL                                                   'sprintf'
         68        INIT_FCALL                                                   'array_merge'
   22    69        IS_SMALLER                                                   1, !6
         70      > JMPZ                                                         ~43, ->73
         71    >   QM_ASSIGN                                            ~44     'parameters%3A'
         72      > JMP                                                          ->74
         73    >   QM_ASSIGN                                            ~44     'parameter%3A'
         74    >   CONCAT                                               ~45     'Required+', ~44
   23    75        INIT_FCALL                                                   'str_repeat'
         76        SEND_VAL                                                     '%25s'
         77        SEND_VAR                                                     !6
         78        DO_ICALL                                             $46     
         79        CONCAT                                               ~47     ~45, $46
         80        IS_SMALLER                                                   1, !6
         81      > JMPZ                                                         ~48, ->84
         82    >   QM_ASSIGN                                            ~49     '+are'
         83      > JMP                                                          ->85
         84    >   QM_ASSIGN                                            ~49     '+is'
         85    >   CONCAT                                               ~50     ~47, ~49
         86        CONCAT                                               ~51     ~50, '+missing'
         87        INIT_ARRAY                                           ~52     ~51
         88        SEND_VAL                                                     ~52
         89        SEND_VAR                                                     !3
   21    90        DO_ICALL                                             $53     
   23    91        SEND_ARRAY                                                   $53
         92        CHECK_UNDEF_ARGS                                             
         93        DO_FCALL                                          1  $54     
         94        SEND_VAR_NO_REF_EX                                           $54
   21    95        DO_FCALL                                          0          
   23    96      > THROW                                             0          $42
   26    97    >   INIT_FCALL                                                   'array_merge'
         98        SEND_VAR                                                     !2
         99        SEND_VAR                                                     !0
        100        DO_ICALL                                             $56     
        101        ASSIGN                                                       !2, $56
   27   102        INIT_FCALL                                                   'extract'
        103        SEND_REF                                                     !2
        104        DO_ICALL                                                     
   29   105        UNSET_CV                                                     !1
        106        UNSET_CV                                                     !3
        107        UNSET_CV                                                     !0
        108        UNSET_CV                                                     !2
        109        UNSET_CV                                                     !5
        110        UNSET_CV                                                     !4
   33   111        ADD                                                  ~59     !7, !8
        112        ADD                                                  ~60     ~59, !9
        113      > RETURN                                                       ~60
   35   114*     > RETURN                                                       null

End of function mysweetcode

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.49 ms | 2261 KiB | 23 Q