3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pages = json_decode('{ "Pages":{ "Home":"Dashboard", "USD Market":{ "Current-Trades":"USD-Current-Trades", "Exchange-Trades":"USD-Exchange-Trades" } } }', true); class Z { private $pages; private $currentPage; public function setConfig($currentPage, array $config) { $this->currentPage = $currentPage; $this->pages = []; $this->addToPageList($config['Pages']); } public function pages($linkName) { return $this->pages[$linkName]; } public function addToPageList(array $pages) { foreach ($pages as $key => $page) { if (is_array($page)) { $this->addToPageList($page); } else { $active = ($page == $this->currentPage) ? 'active' : 'inactive'; $this->pages[$page] = $active; } } } } $z = new Z(); $z->setConfig('USD-Exchange-Trades', $pages); // current page, page config echo $z->pages('USD-Exchange-Trades') . "\n"; echo $z->pages('USD-Current-Trades') . "\n"; echo $z->pages('Dashboard') . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PtAiF
function name:  (null)
number of ops:  28
compiled vars:  !0 = $pages, !1 = $z
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%7B%0A++++%22Pages%22%3A%7B%0A++++++++%22Home%22%3A%22Dashboard%22%2C%0A++++++++%22USD+Market%22%3A%7B%0A++++++++++++%22Current-Trades%22%3A%22USD-Current-Trades%22%2C%0A++++++++++++%22Exchange-Trades%22%3A%22USD-Exchange-Trades%22%0A++++++++%7D%0A++++%7D%0A%7D'
   11     2        SEND_VAL                                                 <true>
    3     3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   44     5        NEW                                              $4      'Z'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $4
   45     8        INIT_METHOD_CALL                                         !1, 'setConfig'
          9        SEND_VAL_EX                                              'USD-Exchange-Trades'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
   46    12        INIT_METHOD_CALL                                         !1, 'pages'
         13        SEND_VAL_EX                                              'USD-Exchange-Trades'
         14        DO_FCALL                                      0  $8      
         15        CONCAT                                           ~9      $8, '%0A'
         16        ECHO                                                     ~9
   47    17        INIT_METHOD_CALL                                         !1, 'pages'
         18        SEND_VAL_EX                                              'USD-Current-Trades'
         19        DO_FCALL                                      0  $10     
         20        CONCAT                                           ~11     $10, '%0A'
         21        ECHO                                                     ~11
   48    22        INIT_METHOD_CALL                                         !1, 'pages'
         23        SEND_VAL_EX                                              'Dashboard'
         24        DO_FCALL                                      0  $12     
         25        CONCAT                                           ~13     $12, '%0A'
         26        ECHO                                                     ~13
         27      > RETURN                                                   1

Class Z:
Function setconfig:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PtAiF
function name:  setConfig
number of ops:  12
compiled vars:  !0 = $currentPage, !1 = $config
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        ASSIGN_OBJ                                               'currentPage'
          3        OP_DATA                                                  !0
   22     4        ASSIGN_OBJ                                               'pages'
          5        OP_DATA                                                  <array>
   23     6        INIT_METHOD_CALL                                         'addToPageList'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $4      !1, 'Pages'
          9        SEND_FUNC_ARG                                            $4
         10        DO_FCALL                                      0          
   24    11      > RETURN                                                   null

End of function setconfig

Function pages:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PtAiF
function name:  pages
number of ops:  5
compiled vars:  !0 = $linkName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        FETCH_OBJ_R                                      ~1      'pages'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   29     4*     > RETURN                                                   null

End of function pages

Function addtopagelist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 21
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/PtAiF
function name:  addToPageList
number of ops:  23
compiled vars:  !0 = $pages, !1 = $page, !2 = $key, !3 = $active
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1      > FE_RESET_R                                       $4      !0, ->21
          2    > > FE_FETCH_R                                       ~5      $4, !1, ->21
          3    >   ASSIGN                                                   !2, ~5
   34     4        TYPE_CHECK                                  128          !1
          5      > JMPZ                                                     ~7, ->10
   35     6    >   INIT_METHOD_CALL                                         'addToPageList'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
   34     9      > JMP                                                      ->20
   37    10    >   FETCH_OBJ_R                                      ~9      'currentPage'
         11        IS_EQUAL                                                 !1, ~9
         12      > JMPZ                                                     ~10, ->15
         13    >   QM_ASSIGN                                        ~11     'active'
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~11     'inactive'
         16    >   ASSIGN                                                   !3, ~11
   38    17        FETCH_OBJ_W                                      $13     'pages'
         18        ASSIGN_DIM                                               $13, !1
         19        OP_DATA                                                  !3
   33    20    > > JMP                                                      ->2
         21    >   FE_FREE                                                  $4
   41    22      > RETURN                                                   null

End of function addtopagelist

End of class Z.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.95 ms | 1009 KiB | 14 Q