3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DataTransferObject { public static function fromParams(array $params); public function asArray(); } trait ImmutableFromParams { private $mutable = true; private function __construct(array $params) { foreach ($params as $key => $value) { $this->{'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))}($value); } unset($this->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 (isset($this->mutable) && substr($method, 0, 3) == 'set' && property_exists($this, lcfirst(substr($method, 3)))) { $this->{lcfirst(substr($method, 3))} = reset($args); } } } abstract class Command { use ImmutableFromParams; } final class MyCommand extends Command implements DataTransferObject { 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/VbIhT
function name:  (null)
number of ops:  16
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   DECLARE_CLASS                                            'command'
   48     1        DECLARE_CLASS                                            'mycommand', 'command'
   60     2        INIT_STATIC_METHOD_CALL                                  'MyCommand', 'fromParams'
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0  $1      
          5        ASSIGN                                                   !0, $1
   62     6        INIT_METHOD_CALL                                         !0, 'setFoo'
          7        SEND_VAL_EX                                              'newfoo'
          8        DO_FCALL                                      0          
   63     9        INIT_METHOD_CALL                                         !0, 'setDog'
         10        SEND_VAL_EX                                              'dog'
         11        DO_FCALL                                      0          
   65    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Class DataTransferObject:
Function fromparams:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VbIhT
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/VbIhT
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 ImmutableFromParams:
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/VbIhT
function name:  __construct
number of ops:  25
compiled vars:  !0 = $params, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1      > FE_RESET_R                                       $3      !0, ->22
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->22
          3    >   ASSIGN                                                   !2, ~4
   19     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                                         $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                         $7      
         15        SEND_VAR                                                 $7
         16        DO_ICALL                                         $8      
         17        CONCAT                                           ~9      'set', $8
         18        INIT_METHOD_CALL                                         ~9
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0          
   17    21      > JMP                                                      ->2
         22    >   FE_FREE                                                  $3
   22    23        UNSET_OBJ                                                'mutable'
   23    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/VbIhT
function name:  fromParams
number of ops:  6
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        NEW                          static              $1      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
   28     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/VbIhT
function name:  asArray
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   33     5*     > RETURN                                                   null

End of function asarray

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

End of function __call

End of class ImmutableFromParams.

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/VbIhT
function name:  setBar
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
   57     3      > RETURN                                                   null

End of function setbar

End of class MyCommand.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.32 ms | 1404 KiB | 29 Q