3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* what I want to achieve*/ $rules= [ 'title' => 'required|min:2|max:5', ]; /////////////////////////////////////////// $types = ['min' => 2, 'max' => 5, 'required'=> 1]; function noValue(array $types):? string{ foreach($types as $key=>$value) { if($key === 'required' ||$value > 0){ return 'required'; } } return null; } function ruleTypes(array $types){ $arr = []; foreach($types as $key => $value) { $arr[] = noValue($types) ? $key . ':' . $value : 'hello'; } return implode('|', $arr); } $arrayOfRules = [ 'title' => ruleTypes($types), ]; var_dump($arrayOfRules);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HtMo3
function name:  (null)
number of ops:  11
compiled vars:  !0 = $rules, !1 = $types, !2 = $arrayOfRules
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   29     2        INIT_FCALL                                               'ruletypes'
          3        SEND_VAR                                                 !1
          4        DO_FCALL                                      0  $5      
          5        INIT_ARRAY                                       ~6      $5, 'title'
   28     6        ASSIGN                                                   !2, ~6
   33     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function novalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
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 = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/HtMo3
function name:  noValue
number of ops:  16
compiled vars:  !0 = $types, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->12
          3    >   ASSIGN                                                   !2, ~4
   12     4        IS_IDENTICAL                                     ~6      !2, 'required'
          5      > JMPNZ_EX                                         ~6      ~6, ->8
          6    >   IS_SMALLER                                       ~7      0, !1
          7        BOOL                                             ~6      ~7
          8    > > JMPZ                                                     ~6, ->11
   13     9    >   FE_FREE                                                  $3
         10      > RETURN                                                   'required'
   11    11    > > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   16    13      > RETURN                                                   null
   17    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function novalue

Function ruletypes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/HtMo3
function name:  ruleTypes
number of ops:  24
compiled vars:  !0 = $types, !1 = $arr, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        ASSIGN                                                   !1, <array>
   21     2      > FE_RESET_R                                       $5      !0, ->17
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->17
          4    >   ASSIGN                                                   !3, ~6
   22     5        INIT_FCALL                                               'novalue'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $9      
          8      > JMPZ                                                     $9, ->13
          9    >   CONCAT                                           ~10     !3, '%3A'
         10        CONCAT                                           ~11     ~10, !2
         11        QM_ASSIGN                                        ~12     ~11
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~12     'hello'
         14    >   ASSIGN_DIM                                               !1
         15        OP_DATA                                                  ~12
   21    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $5
   25    18        INIT_FCALL                                               'implode'
         19        SEND_VAL                                                 '%7C'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $13     
         22      > RETURN                                                   $13
   26    23*     > RETURN                                                   null

End of function ruletypes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.44 ms | 1403 KiB | 19 Q