3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ClassPrivateAccessor { /** @var \Closure */ private static $getter; /** @var \Closure */ private static $setter; private static $setterMany; /** @var \Closure */ private $contexGetter; /** @var \Closure */ private $contexSetter; private $contextSetterMany; public static function initAccessor() { ClassPrivateAccessor::$getter = function($fieldName) { return $this->$fieldName; }; ClassPrivateAccessor::$setter = function($fieldName, $newValue) { $this->$fieldName = $newValue; }; ClassPrivateAccessor::$setterMany = function(array $values) { foreach ($values as $field => $value) { $this->$field = $value; } }; } public function setContextForGetter($context) { $this->contexGetter = Closure::bind(ClassPrivateAccessor::$getter,$context, $context); } public function setContextForSetter($context) { $this->contexSetter = ClassPrivateAccessor::$setter->bindTo($context, $context); } public function setContextForSetterMany($context) { $this->contextSetterMany = ClassPrivateAccessor::$setterMany->bindTo($context, $context); } public function get($fieldName) { return $this->contexGetter($fieldName); } public function set($fieldName, $newValue) { $this->contexSetter($fieldName, $newValue); } public function setMany($values) { $this->contextSetterMany($values); } } ClassPrivateAccessor::initAccessor(); $accessor = new ClassPrivateAccessor(); class Foo { private $test1; private $test2; private $test3; } $foo = new Foo(); $accessor->setContextForSetter($foo); $accessor->set('test1',10);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  (null)
number of ops:  16
compiled vars:  !0 = $accessor, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   INIT_STATIC_METHOD_CALL                                  'ClassPrivateAccessor', 'initAccessor'
          1        DO_FCALL                                      0          
   63     2        NEW                                              $3      'ClassPrivateAccessor'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   71     5        NEW                                              $6      'Foo'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
   72     8        INIT_METHOD_CALL                                         !0, 'setContextForSetter'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   73    11        INIT_METHOD_CALL                                         !0, 'set'
         12        SEND_VAL_EX                                              'test1'
         13        SEND_VAL_EX                                              10
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FOSCfS%3A20%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $fieldName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_R                                      ~2      $1, !0
          3      > RETURN                                                   ~2
   22     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOSCfS%3A20%240

Function %00%7Bclosure%7D%2Fin%2FOSCfS%3A24%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $fieldName, !1 = $newValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        FETCH_THIS                                       $2      
          3        ASSIGN_OBJ                                               $2, !0
          4        OP_DATA                                                  !1
   26     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOSCfS%3A24%241

Function %00%7Bclosure%7D%2Fin%2FOSCfS%3A28%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/OSCfS
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $values, !1 = $value, !2 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1      > FE_RESET_R                                       $3      !0, ->8
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->8
          3    >   ASSIGN                                                   !2, ~4
   30     4        FETCH_THIS                                       $6      
          5        ASSIGN_OBJ                                               $6, !2
          6        OP_DATA                                                  !1
   29     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $3
   32     9      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FOSCfS%3A28%242

Class ClassPrivateAccessor:
Function initaccessor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  initAccessor
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOSCfS%3A20%240'
          1        ASSIGN_STATIC_PROP                                       'getter', 'ClassPrivateAccessor'
   22     2        OP_DATA                                                  ~1
   24     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOSCfS%3A24%241'
          4        ASSIGN_STATIC_PROP                                       'setter', 'ClassPrivateAccessor'
   26     5        OP_DATA                                                  ~3
   28     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOSCfS%3A28%242'
          7        ASSIGN_STATIC_PROP                                       'setterMany', 'ClassPrivateAccessor'
   32     8        OP_DATA                                                  ~5
   33     9      > RETURN                                                   null

End of function initaccessor

Function setcontextforgetter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  setContextForGetter
number of ops:  10
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          2        FETCH_STATIC_PROP_R          unknown             ~2      'getter'
          3        SEND_VAL                                                 ~2
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $3      
          7        ASSIGN_OBJ                                               'contexGetter'
          8        OP_DATA                                                  $3
          9      > RETURN                                                   null

End of function setcontextforgetter

Function setcontextforsetter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  setContextForSetter
number of ops:  9
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        FETCH_STATIC_PROP_R          unknown             ~2      'setter'
          2        INIT_METHOD_CALL                                         ~2, 'bindTo'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN_OBJ                                               'contexSetter'
          7        OP_DATA                                                  $3
   40     8      > RETURN                                                   null

End of function setcontextforsetter

Function setcontextforsettermany:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  setContextForSetterMany
number of ops:  9
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        FETCH_STATIC_PROP_R          unknown             ~2      'setterMany'
          2        INIT_METHOD_CALL                                         ~2, 'bindTo'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN_OBJ                                               'contextSetterMany'
          7        OP_DATA                                                  $3
   44     8      > RETURN                                                   null

End of function setcontextforsettermany

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  get
number of ops:  6
compiled vars:  !0 = $fieldName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        INIT_METHOD_CALL                                         'contexGetter'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   48     5*     > RETURN                                                   null

End of function get

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  set
number of ops:  7
compiled vars:  !0 = $fieldName, !1 = $newValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   51     2        INIT_METHOD_CALL                                         'contexSetter'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   52     6      > RETURN                                                   null

End of function set

Function setmany:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OSCfS
function name:  setMany
number of ops:  5
compiled vars:  !0 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   55     1        INIT_METHOD_CALL                                         'contextSetterMany'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   56     4      > RETURN                                                   null

End of function setmany

End of class ClassPrivateAccessor.

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.01 ms | 1407 KiB | 13 Q