3v4l.org

run code in 300+ PHP versions simultaneously
<?php class FilterQuery { protected $filters = []; public function __construct(string $filter) { $this->parseFilters($filter); } private function parseFilters(string $filter) { $filters = explode(';', $filter); foreach ($filters as $splitFilter) { $this->parseFilter($splitFilter); } } private function parseFilter(string $filter) { $splitFilter = explode(':', $filter); if (count($splitFilter) < 2) { return; } $this->filters[$splitFilter[0]] = $this->parseFilterValues($splitFilter[1]); } private function parseFilterValues(string $values) : array { return explode(',', $values); } public function getFilter($filterName) : array { if (!array_key_exists($filterName, $this->filters)) { return []; } return $this->filters[$filterName]; } } $filter = new FilterQuery('loginType:1,2;ipAddress:192.168.254.249'); print_r($filter->getFilter('loginType')); print_r($filter->getFilter('ipAddress')); print_r($filter->getFilter('username'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NSjll
function name:  (null)
number of ops:  23
compiled vars:  !0 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $1      'FilterQuery'
          1        SEND_VAL_EX                                              'loginType%3A1%2C2%3BipAddress%3A192.168.254.249'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   44     4        INIT_FCALL                                               'print_r'
          5        INIT_METHOD_CALL                                         !0, 'getFilter'
          6        SEND_VAL_EX                                              'loginType'
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                                 
   45    10        INIT_FCALL                                               'print_r'
         11        INIT_METHOD_CALL                                         !0, 'getFilter'
         12        SEND_VAL_EX                                              'ipAddress'
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                                 
   46    16        INIT_FCALL                                               'print_r'
         17        INIT_METHOD_CALL                                         !0, 'getFilter'
         18        SEND_VAL_EX                                              'username'
         19        DO_FCALL                                      0  $8      
         20        SEND_VAR                                                 $8
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Class FilterQuery:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NSjll
function name:  __construct
number of ops:  5
compiled vars:  !0 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        INIT_METHOD_CALL                                         'parseFilters'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
    8     4      > RETURN                                                   null

End of function __construct

Function parsefilters:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/NSjll
function name:  parseFilters
number of ops:  14
compiled vars:  !0 = $filter, !1 = $filters, !2 = $splitFilter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%3B'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   14     6      > FE_RESET_R                                       $5      !1, ->12
          7    > > FE_FETCH_R                                               $5, !2, ->12
   15     8    >   INIT_METHOD_CALL                                         'parseFilter'
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
   14    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $5
   17    13      > RETURN                                                   null

End of function parsefilters

Function parsefilter:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NSjll
function name:  parseFilter
number of ops:  20
compiled vars:  !0 = $filter, !1 = $splitFilter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%3A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   22     6        COUNT                                            ~4      !1
          7        IS_SMALLER                                               ~4, 2
          8      > JMPZ                                                     ~5, ->10
   23     9    > > RETURN                                                   null
   26    10    >   FETCH_DIM_R                                      ~7      !1, 0
         11        INIT_METHOD_CALL                                         'parseFilterValues'
         12        CHECK_FUNC_ARG                                           
         13        FETCH_DIM_FUNC_ARG                               $9      !1, 1
         14        SEND_FUNC_ARG                                            $9
         15        DO_FCALL                                      0  $10     
         16        FETCH_OBJ_W                                      $6      'filters'
         17        ASSIGN_DIM                                               $6, ~7
         18        OP_DATA                                                  $10
   27    19      > RETURN                                                   null

End of function parsefilter

Function parsefiltervalues:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NSjll
function name:  parseFilterValues
number of ops:  9
compiled vars:  !0 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2C'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        VERIFY_RETURN_TYPE                                       $1
          6      > RETURN                                                   $1
   31     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function parsefiltervalues

Function getfilter:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NSjll
function name:  getFilter
number of ops:  12
compiled vars:  !0 = $filterName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        FETCH_OBJ_R                                      ~1      'filters'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->6
   35     5    > > RETURN                                                   <array>
   38     6    >   FETCH_OBJ_R                                      ~4      'filters'
          7        FETCH_DIM_R                                      ~5      ~4, !0
          8        VERIFY_RETURN_TYPE                                       ~5
          9      > RETURN                                                   ~5
   39    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function getfilter

End of class FilterQuery.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.33 ms | 1404 KiB | 17 Q