3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { private $id; private $username; } class Hydrator { private $propertyMap = array(); private $valueFilters = array(); public function setPropertyMap(array $propertyMap) { $this->propertyMap = $propertyMap; } public function setValueFilters(array $filters) { $this->valueFilters = $filters; } public function generate() { $propertyMap = $this->propertyMap; $valueFilters = $this->valueFilters; return function (array $row) use ($propertyMap, $valueFilters) { var_dump($this); foreach ($row as $k => $v) { $property = isset($propertyMap[$k]) ? $propertyMap[$k] : $k; $value = isset($valueFilters[$k]) ? $valueFilters[$k]($v) : $v; $this->{$property} = $value; } }; } public function hydrate($obj, array $data) { $fn = $this->generate()->bindTo($obj, $obj); $fn($data); return $obj; } } class MySqlUserMapper { public function fetchByUsername($username) { $row = array( 'id' => '1', 'username' => $username, ); $user = new User; $this->hydrate($user, $row); return $user; } private function hydrate(User $user, array $row) { static $hydrator; if (!$hydrator) { $hydrator = new Hydrator(); $hydrator->setValueFilters(array( 'id' => 'intval' )); } return $hydrator->hydrate($user, $row); } } $mapper = new MySqlUserMapper(); var_dump($mapper->fetchByUsername('mabe'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OsOX3
function name:  (null)
number of ops:  10
compiled vars:  !0 = $mapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   NEW                                              $1      'MySqlUserMapper'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   71     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'fetchByUsername'
          5        SEND_VAL_EX                                              'mabe'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FOsOX3%3A27%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 31
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 31
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
Branch analysis from position: 25
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/OsOX3
function name:  {closure}
number of ops:  33
compiled vars:  !0 = $row, !1 = $propertyMap, !2 = $valueFilters, !3 = $v, !4 = $k, !5 = $property, !6 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   28     3        INIT_FCALL                                               'var_dump'
          4        FETCH_THIS                                       ~7      
          5        SEND_VAL                                                 ~7
          6        DO_ICALL                                                 
   29     7      > FE_RESET_R                                       $9      !0, ->31
          8    > > FE_FETCH_R                                       ~10     $9, !3, ->31
          9    >   ASSIGN                                                   !4, ~10
   30    10        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !4
         11      > JMPZ                                                     ~12, ->15
         12    >   FETCH_DIM_R                                      ~13     !1, !4
         13        QM_ASSIGN                                        ~14     ~13
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~14     !4
         16    >   ASSIGN                                                   !5, ~14
   31    17        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !4
         18      > JMPZ                                                     ~16, ->25
         19    >   FETCH_DIM_R                                      ~17     !2, !4
         20        INIT_DYNAMIC_CALL                                        ~17
         21        SEND_VAR_EX                                              !3
         22        DO_FCALL                                      0  $18     
         23        QM_ASSIGN                                        ~19     $18
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~19     !3
         26    >   ASSIGN                                                   !6, ~19
   32    27        FETCH_THIS                                       $21     
         28        ASSIGN_OBJ                                               $21, !5
         29        OP_DATA                                                  !6
   29    30      > JMP                                                      ->8
         31    >   FE_FREE                                                  $9
   34    32      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOsOX3%3A27%240

Class User: [no user functions]
Class Hydrator:
Function setpropertymap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OsOX3
function name:  setPropertyMap
number of ops:  4
compiled vars:  !0 = $propertyMap
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        ASSIGN_OBJ                                               'propertyMap'
          2        OP_DATA                                                  !0
   16     3      > RETURN                                                   null

End of function setpropertymap

Function setvaluefilters:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OsOX3
function name:  setValueFilters
number of ops:  4
compiled vars:  !0 = $filters
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        ASSIGN_OBJ                                               'valueFilters'
          2        OP_DATA                                                  !0
   21     3      > RETURN                                                   null

End of function setvaluefilters

Function generate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OsOX3
function name:  generate
number of ops:  9
compiled vars:  !0 = $propertyMap, !1 = $valueFilters
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   FETCH_OBJ_R                                      ~2      'propertyMap'
          1        ASSIGN                                                   !0, ~2
   26     2        FETCH_OBJ_R                                      ~4      'valueFilters'
          3        ASSIGN                                                   !1, ~4
   27     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOsOX3%3A27%240'
          5        BIND_LEXICAL                                             ~6, !0
          6        BIND_LEXICAL                                             ~6, !1
   34     7      > RETURN                                                   ~6
   35     8*     > RETURN                                                   null

End of function generate

Function hydrate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OsOX3
function name:  hydrate
number of ops:  14
compiled vars:  !0 = $obj, !1 = $data, !2 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        INIT_METHOD_CALL                                         'generate'
          3        DO_FCALL                                      0  $3      
          4        INIT_METHOD_CALL                                         $3, 'bindTo'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !2, $4
   40     9        INIT_DYNAMIC_CALL                                        !2
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
   41    12      > RETURN                                                   !0
   42    13*     > RETURN                                                   null

End of function hydrate

End of class Hydrator.

Class MySqlUserMapper:
Function fetchbyusername:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OsOX3
function name:  fetchByUsername
number of ops:  13
compiled vars:  !0 = $username, !1 = $row, !2 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        INIT_ARRAY                                       ~3      '1', 'id'
   49     2        ADD_ARRAY_ELEMENT                                ~3      !0, 'username'
   47     3        ASSIGN                                                   !1, ~3
   51     4        NEW                                              $5      'User'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $5
   52     7        INIT_METHOD_CALL                                         'hydrate'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   53    11      > RETURN                                                   !2
   54    12*     > RETURN                                                   null

End of function fetchbyusername

Function hydrate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/OsOX3
function name:  hydrate
number of ops:  17
compiled vars:  !0 = $user, !1 = $row, !2 = $hydrator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2        BIND_STATIC                                              !2
   59     3        BOOL_NOT                                         ~3      !2
          4      > JMPZ                                                     ~3, ->11
   60     5    >   NEW                                              $4      'Hydrator'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $4
   61     8        INIT_METHOD_CALL                                         !2, 'setValueFilters'
   62     9        SEND_VAL_EX                                              <array>
         10        DO_FCALL                                      0          
   66    11    >   INIT_METHOD_CALL                                         !2, 'hydrate'
         12        SEND_VAR_EX                                              !0
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $8      
         15      > RETURN                                                   $8
   67    16*     > RETURN                                                   null

End of function hydrate

End of class MySqlUserMapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.18 ms | 1400 KiB | 15 Q