3v4l.org

run code in 300+ PHP versions simultaneously
<?php $config = [ 'legendaryName' => [ 'column' => 'legendary_name', 'type' => 'string', ] ]; $data = ['legendary_name' => 'The Hammer']; class Warrior { use DbHydrate; private $legendaryName; } trait DbHydrate { public function extract($config) { $row = []; foreach($config as $attributeName => $column) { if(property_exists($this, $attributeName)) { $columnName = $attributeConfig['column']; $row[$columnName] = $this->{$attributeName}; } else { throw new \Exception(sprintf('The property %s does not exists in %s', $attributeName, self::class)); } } return $row; } public function hydrate($config, $data) { foreach($config as $attributeName => $attributeConfig) { if(property_exists($this, $attributeName)) { $columnName = $attributeConfig['column']; $value = $data[$columnName]; if ($attributeConfig['type'] === 'string' && is_string($value)) { $this->{$attributeName} = $value; } } else { throw new \Exception(sprintf('The property %s does not exists in %s', $attributeName, self::class)); } } } } $legendaryWarrior = new Warrior; $legendaryWarrior->hydrate($config, $data); var_dump($legendaryWarrior->extract($config)); var_dump($legendaryWarrior); /* $config = ['classicalName' => 'classical_name']; $data = ['classical_name' => 'John']; $testWarrior = new Warrior; $testWarrior->hydrate($config, $data); var_dump($testWarrior);*/
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bDRq5
function name:  (null)
number of ops:  20
compiled vars:  !0 = $config, !1 = $data, !2 = $legendaryWarrior
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   12     2        DECLARE_CLASS                                            'warrior'
   53     3        NEW                                              $5      'Warrior'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $5
   54     6        INIT_METHOD_CALL                                         !2, 'hydrate'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
   55    10        INIT_FCALL                                               'var_dump'
         11        INIT_METHOD_CALL                                         !2, 'extract'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                                 
   56    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                                 
   64    19      > RETURN                                                   1

Class Warrior: [no user functions]
Class DbHydrate:
Function extract:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/bDRq5
function name:  extract
number of ops:  31
compiled vars:  !0 = $config, !1 = $row, !2 = $column, !3 = $attributeName, !4 = $columnName, !5 = $attributeConfig
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, <array>
   23     2      > FE_RESET_R                                       $7      !0, ->28
          3    > > FE_FETCH_R                                       ~8      $7, !2, ->28
          4    >   ASSIGN                                                   !3, ~8
   25     5        INIT_FCALL                                               'property_exists'
          6        FETCH_THIS                                       ~10     
          7        SEND_VAL                                                 ~10
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $11     
         10      > JMPZ                                                     $11, ->17
   26    11    >   FETCH_DIM_R                                      ~12     !5, 'column'
         12        ASSIGN                                                   !4, ~12
   27    13        FETCH_OBJ_R                                      ~15     !3
         14        ASSIGN_DIM                                               !1, !4
         15        OP_DATA                                                  ~15
         16      > JMP                                                      ->27
   29    17    >   NEW                                              $16     'Exception'
         18        INIT_FCALL                                               'sprintf'
         19        SEND_VAL                                                 'The+property+%25s+does+not+exists+in+%25s'
         20        SEND_VAR                                                 !3
         21        FETCH_CLASS_NAME                                 ~17     
         22        SEND_VAL                                                 ~17
         23        DO_ICALL                                         $18     
         24        SEND_VAR_NO_REF_EX                                       $18
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $16
   23    27    > > JMP                                                      ->3
         28    >   FE_FREE                                                  $7
   32    29      > RETURN                                                   !1
   33    30*     > RETURN                                                   null

End of function extract

Function hydrate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 23
Branch analysis from position: 20
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/bDRq5
function name:  hydrate
number of ops:  37
compiled vars:  !0 = $config, !1 = $data, !2 = $attributeConfig, !3 = $attributeName, !4 = $columnName, !5 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2      > FE_RESET_R                                       $6      !0, ->35
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->35
          4    >   ASSIGN                                                   !3, ~7
   39     5        INIT_FCALL                                               'property_exists'
          6        FETCH_THIS                                       ~9      
          7        SEND_VAL                                                 ~9
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $10     
         10      > JMPZ                                                     $10, ->24
   40    11    >   FETCH_DIM_R                                      ~11     !2, 'column'
         12        ASSIGN                                                   !4, ~11
   41    13        FETCH_DIM_R                                      ~13     !1, !4
         14        ASSIGN                                                   !5, ~13
   42    15        FETCH_DIM_R                                      ~15     !2, 'type'
         16        IS_IDENTICAL                                     ~16     ~15, 'string'
         17      > JMPZ_EX                                          ~16     ~16, ->20
         18    >   TYPE_CHECK                                   64  ~17     !5
         19        BOOL                                             ~16     ~17
         20    > > JMPZ                                                     ~16, ->23
   43    21    >   ASSIGN_OBJ                                               !3
         22        OP_DATA                                                  !5
         23    > > JMP                                                      ->34
   46    24    >   NEW                                              $19     'Exception'
         25        INIT_FCALL                                               'sprintf'
         26        SEND_VAL                                                 'The+property+%25s+does+not+exists+in+%25s'
         27        SEND_VAR                                                 !3
         28        FETCH_CLASS_NAME                                 ~20     
         29        SEND_VAL                                                 ~20
         30        DO_ICALL                                         $21     
         31        SEND_VAR_NO_REF_EX                                       $21
         32        DO_FCALL                                      0          
         33      > THROW                                         0          $19
   37    34    > > JMP                                                      ->3
         35    >   FE_FREE                                                  $6
   49    36      > RETURN                                                   null

End of function hydrate

End of class DbHydrate.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.15 ms | 1404 KiB | 19 Q