3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataHolder { private $rawData; private $parsedData; private $mapping = [ 'dbField1' => 'outputField1', 'dbField2' => ['outputField2' => ['parseFn1', 'parseFn2']] ]; private function parserFn1($value) { return $value * 2; } private function parserFn2($value) { return $value . "$"; } public function __construct(array $data) { $this->rawData = $data; $this->mapData(); } // Yes, I know the methods shouldn't be here but it rather be decoupled in another class and // injected with a DI it but I wrote it like this with example purposes only private function mapData() { foreach($this->mapping as $dbFieldName => $content) { if(isset($this->rawData[$dbFieldName])) { if(is_string($content)) { $parsedData[$content] = $this->rawData[$dbFieldName]; } else if (is_array($content)) { $frontFieldName = key($content); $functionsArray = reset($content); $value = $this->rawData[$dbFieldName]; foreach($functionsArray as $functionName) { if(method_exists(DataHolder::class, $functionName)) { var_dump($functionName); } } } } } } } $data = ['dbField1' => 5, 'dbField2' => 13]; $dh = new DataHolder($data);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W2TG2
function name:  (null)
number of ops:  6
compiled vars:  !0 = $data, !1 = $dh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   ASSIGN                                                   !0, <array>
   52     1        NEW                                              $3      'DataHolder'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
          5      > RETURN                                                   1

Class DataHolder:
Function parserfn1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W2TG2
function name:  parserFn1
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   13     3*     > RETURN                                                   null

End of function parserfn1

Function parserfn2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W2TG2
function name:  parserFn2
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        CONCAT                                           ~1      !0, '%24'
          2      > RETURN                                                   ~1
   17     3*     > RETURN                                                   null

End of function parserfn2

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W2TG2
function name:  __construct
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        ASSIGN_OBJ                                               'rawData'
          2        OP_DATA                                                  !0
   21     3        INIT_METHOD_CALL                                         'mapData'
          4        DO_FCALL                                      0          
   22     5      > RETURN                                                   null

End of function __construct

Function mapdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 40
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 40
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 39
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 39
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 38
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 38
Branch analysis from position: 39
Branch analysis from position: 39
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/W2TG2
function name:  mapData
number of ops:  42
compiled vars:  !0 = $content, !1 = $dbFieldName, !2 = $parsedData, !3 = $frontFieldName, !4 = $functionsArray, !5 = $value, !6 = $functionName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~7      'mapping'
          1      > FE_RESET_R                                       $8      ~7, ->40
          2    > > FE_FETCH_R                                       ~9      $8, !0, ->40
          3    >   ASSIGN                                                   !1, ~9
   29     4        FETCH_OBJ_IS                                     ~11     'rawData'
          5        ISSET_ISEMPTY_DIM_OBJ                         0          ~11, !1
          6      > JMPZ                                                     ~12, ->39
   31     7    >   TYPE_CHECK                                   64          !0
          8      > JMPZ                                                     ~13, ->14
   32     9    >   FETCH_OBJ_R                                      ~15     'rawData'
         10        FETCH_DIM_R                                      ~16     ~15, !1
         11        ASSIGN_DIM                                               !2, !0
         12        OP_DATA                                                  ~16
         13      > JMP                                                      ->39
   34    14    >   TYPE_CHECK                                  128          !0
         15      > JMPZ                                                     ~17, ->39
   35    16    >   INIT_FCALL                                               'key'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $18     
         19        ASSIGN                                                   !3, $18
   36    20        INIT_FCALL                                               'reset'
         21        SEND_REF                                                 !0
         22        DO_ICALL                                         $20     
         23        ASSIGN                                                   !4, $20
   37    24        FETCH_OBJ_R                                      ~22     'rawData'
         25        FETCH_DIM_R                                      ~23     ~22, !1
         26        ASSIGN                                                   !5, ~23
   39    27      > FE_RESET_R                                       $25     !4, ->38
         28    > > FE_FETCH_R                                               $25, !6, ->38
   40    29    >   INIT_FCALL                                               'method_exists'
         30        SEND_VAL                                                 'DataHolder'
         31        SEND_VAR                                                 !6
         32        DO_ICALL                                         $26     
         33      > JMPZ                                                     $26, ->37
   41    34    >   INIT_FCALL                                               'var_dump'
         35        SEND_VAR                                                 !6
         36        DO_ICALL                                                 
   39    37    > > JMP                                                      ->28
         38    >   FE_FREE                                                  $25
   27    39    > > JMP                                                      ->2
         40    >   FE_FREE                                                  $8
   48    41      > RETURN                                                   null

End of function mapdata

End of class DataHolder.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.78 ms | 1396 KiB | 21 Q