3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DataTransferObject { public static function fromParams(array $params); public function asArray(); } trait DataTransferTrait { private static $mutable = true; private function __construct(array $params) { foreach ($params as $key => $value) { $this->{'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))}($value); } unset($mutable); } public static function fromParams(array $params) { return new static($params); } public function asArray() { return get_object_vars($this); } public function __call($method, $args) { if ($this->mutable == true && substr($method, 0, 3) == 'set' && property_exists($this, lcfirst(substr($method, 3)))) { $this->{lcfirst(substr($method, 3))} = reset($args); } } } abstract class Command { } final class MyCommand extends Command implements DataTransferObject { use DataTransferTrait; private $foo; private $bar; private function setBar($value) { $this->bar = $value; } } $foo = MyCommand::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); var_dump($foo);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4keki
function name:  (null)
number of ops:  15
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   DECLARE_CLASS                                            'mycommand', 'command'
   61     1        INIT_STATIC_METHOD_CALL                                  'MyCommand', 'fromParams'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   63     5        INIT_METHOD_CALL                                         !0, 'setFoo'
          6        SEND_VAL_EX                                              'newfoo'
          7        DO_FCALL                                      0          
   64     8        INIT_METHOD_CALL                                         !0, 'setDog'
          9        SEND_VAL_EX                                              'dog'
         10        DO_FCALL                                      0          
   66    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Class DataTransferObject:
Function fromparams:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4keki
function name:  fromParams
number of ops:  2
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function fromparams

Function asarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4keki
function name:  asArray
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E > > RETURN                                                   null

End of function asarray

End of class DataTransferObject.

Class DataTransferTrait:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 22
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/4keki
function name:  __construct
number of ops:  25
compiled vars:  !0 = $params, !1 = $value, !2 = $key, !3 = $mutable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1      > FE_RESET_R                                       $4      !0, ->22
          2    > > FE_FETCH_R                                       ~5      $4, !1, ->22
          3    >   ASSIGN                                                   !2, ~5
   18     4        INIT_FCALL                                               'str_replace'
          5        SEND_VAL                                                 '+'
          6        SEND_VAL                                                 ''
          7        INIT_FCALL                                               'ucwords'
          8        INIT_FCALL                                               'str_replace'
          9        SEND_VAL                                                 '_'
         10        SEND_VAL                                                 '+'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $7      
         13        SEND_VAR                                                 $7
         14        DO_ICALL                                         $8      
         15        SEND_VAR                                                 $8
         16        DO_ICALL                                         $9      
         17        CONCAT                                           ~10     'set', $9
         18        INIT_METHOD_CALL                                         ~10
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0          
   16    21      > JMP                                                      ->2
         22    >   FE_FREE                                                  $4
   21    23        UNSET_CV                                                 !3
   22    24      > RETURN                                                   null

End of function __construct

Function fromparams:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4keki
function name:  fromParams
number of ops:  6
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        NEW                          static              $1      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
   27     5*     > RETURN                                                   null

End of function fromparams

Function asarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4keki
function name:  asArray
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   32     5*     > RETURN                                                   null

End of function asarray

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 39
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 26
Branch analysis from position: 12
filename:       /in/4keki
function name:  __call
number of ops:  40
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        FETCH_OBJ_R                                      ~2      'mutable'
          3        BOOL                                             ~3      ~2
          4      > JMPZ_EX                                          ~3      ~3, ->12
          5    >   INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 3
          9        DO_ICALL                                         $4      
         10        IS_EQUAL                                         ~5      $4, 'set'
         11        BOOL                                             ~3      ~5
         12    > > JMPZ_EX                                          ~3      ~3, ->26
         13    >   INIT_FCALL                                               'property_exists'
         14        FETCH_THIS                                       ~6      
         15        SEND_VAL                                                 ~6
         16        INIT_FCALL                                               'lcfirst'
         17        INIT_FCALL                                               'substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 3
         20        DO_ICALL                                         $7      
         21        SEND_VAR                                                 $7
         22        DO_ICALL                                         $8      
         23        SEND_VAR                                                 $8
         24        DO_ICALL                                         $9      
         25        BOOL                                             ~3      $9
         26    > > JMPZ                                                     ~3, ->39
   38    27    >   INIT_FCALL                                               'lcfirst'
         28        INIT_FCALL                                               'substr'
         29        SEND_VAR                                                 !0
         30        SEND_VAL                                                 3
         31        DO_ICALL                                         $10     
         32        SEND_VAR                                                 $10
         33        DO_ICALL                                         $11     
         34        INIT_FCALL                                               'reset'
         35        SEND_REF                                                 !1
         36        DO_ICALL                                         $13     
         37        ASSIGN_OBJ                                               $11
         38        OP_DATA                                                  $13
   40    39    > > RETURN                                                   null

End of function __call

End of class DataTransferTrait.

Class Command: [no user functions]
Class MyCommand:
Function setbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4keki
function name:  setBar
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   57     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
   58     3      > RETURN                                                   null

End of function setbar

End of class MyCommand.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
207.66 ms | 1404 KiB | 29 Q