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 = ClassPrivateAccessor::$getter->bindTo($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); $acessor->set('test1',10);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pk4RO
function name:  (null)
number of ops:  16
compiled vars:  !0 = $accessor, !1 = $foo, !2 = $acessor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_STATIC_METHOD_CALL                                  'ClassPrivateAccessor', 'initAccessor'
          1        DO_FCALL                                      0          
   64     2        NEW                                              $4      'ClassPrivateAccessor'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $4
   72     5        NEW                                              $7      'Foo'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $7
   73     8        INIT_METHOD_CALL                                         !0, 'setContextForSetter'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   74    11        INIT_METHOD_CALL                                         !2, 'set'
         12        SEND_VAL_EX                                              'test1'
         13        SEND_VAL_EX                                              10
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fpk4RO%3A20%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pk4RO
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%2Fpk4RO%3A20%240

Function %00%7Bclosure%7D%2Fin%2Fpk4RO%3A24%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pk4RO
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%2Fpk4RO%3A24%241

Function %00%7Bclosure%7D%2Fin%2Fpk4RO%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/pk4RO
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%2Fpk4RO%3A28%242

Class ClassPrivateAccessor:
Function initaccessor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pk4RO
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%2Fpk4RO%3A20%240'
          1        ASSIGN_STATIC_PROP                                       'getter', 'ClassPrivateAccessor'
   22     2        OP_DATA                                                  ~1
   24     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fpk4RO%3A24%241'
          4        ASSIGN_STATIC_PROP                                       'setter', 'ClassPrivateAccessor'
   26     5        OP_DATA                                                  ~3
   28     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fpk4RO%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/pk4RO
function name:  setContextForGetter
number of ops:  9
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        FETCH_STATIC_PROP_R          unknown             ~2      'getter'
          2        INIT_METHOD_CALL                                         ~2, 'bindTo'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN_OBJ                                               'contexGetter'
          7        OP_DATA                                                  $3
   37     8      > 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/pk4RO
function name:  setContextForSetter
number of ops:  9
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     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
   41     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/pk4RO
function name:  setContextForSetterMany
number of ops:  9
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     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
   45     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/pk4RO
function name:  get
number of ops:  6
compiled vars:  !0 = $fieldName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_METHOD_CALL                                         'contexGetter'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   49     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/pk4RO
function name:  set
number of ops:  7
compiled vars:  !0 = $fieldName, !1 = $newValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   52     2        INIT_METHOD_CALL                                         'contexSetter'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   53     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/pk4RO
function name:  setMany
number of ops:  5
compiled vars:  !0 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   56     1        INIT_METHOD_CALL                                         'contextSetterMany'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   57     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:
195.77 ms | 1407 KiB | 13 Q