3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $foo; protected $bar; protected $baz; } class FooSelfHydratingProxy extends Foo { /** zero-argument constructor since this is just a helper class for hydration */ public function __construct() { } /** * the `Foo` typehint is not part of the interface - here only for the sake of readability/clearness */ public function hydrate($data, Foo $object) { $object->foo = $data['foo']; $object->bar = $data['bar']; $object->baz = $data['baz']; } /** * the `Foo` typehint is not part of the interface - here only for the sake of readability/clearness */ public function extract(Foo $object) { return array('foo' => $object->foo, 'bar' => $object->bar, 'baz' => $object->baz); } } $iterations = 100000; class A {protected $a; protected $b; protected $c;} class AHydrator extends A { public function hydrate(A $a, array $data) { $a->a = $data['a']; $a->b = $data['b']; $a->c = $data['c']; } } $data = array('a' => 1, 'b' => 2, 'c' => 3); $a = new A(); $h = new AHydrator(); for ($i = 0; $i < $iterations; $i++) { $h->hydrate($a, $data); } $iterations = 100000; class A {protected $a; protected $b; protected $c;} $rA = new ReflectionProperty('A', 'a'); $rB = new ReflectionProperty('A', 'b'); $rC = new ReflectionProperty('A', 'c'); $rA->setAccessible(true); $rB->setAccessible(true); $rC->setAccessible(true); $data = array('a' => 1, 'b' => 2, 'c' => 3); $a = new A(); for ($i = 0; $i < $iterations; $i++) { $rA->setValue($a, $data['a']); $rB->setValue($a, $data['b']); $rC->setValue($a, $data['c']); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 49
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 49
Branch analysis from position: 70
Branch analysis from position: 49
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/cTtZJ
function name:  (null)
number of ops:  71
compiled vars:  !0 = $iterations, !1 = $data, !2 = $a, !3 = $h, !4 = $i, !5 = $rA, !6 = $rB, !7 = $rC
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, 100000
   45     1        ASSIGN                                                   !1, <array>
   46     2        NEW                                              $10     'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $10
   47     5        NEW                                              $13     'AHydrator'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !3, $13
   48     8        ASSIGN                                                   !4, 0
          9      > JMP                                                      ->15
   49    10    >   INIT_METHOD_CALL                                         !3, 'hydrate'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0          
   48    14        PRE_INC                                                  !4
         15    >   IS_SMALLER                                               !4, !0
         16      > JMPNZ                                                    ~19, ->10
   52    17    >   ASSIGN                                                   !0, 100000
   53    18        DECLARE_CLASS                                            'a'
   54    19        NEW                                              $21     'ReflectionProperty'
         20        SEND_VAL_EX                                              'A'
         21        SEND_VAL_EX                                              'a'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !5, $21
   55    24        NEW                                              $24     'ReflectionProperty'
         25        SEND_VAL_EX                                              'A'
         26        SEND_VAL_EX                                              'b'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !6, $24
   56    29        NEW                                              $27     'ReflectionProperty'
         30        SEND_VAL_EX                                              'A'
         31        SEND_VAL_EX                                              'c'
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !7, $27
   57    34        INIT_METHOD_CALL                                         !5, 'setAccessible'
         35        SEND_VAL_EX                                              <true>
         36        DO_FCALL                                      0          
   58    37        INIT_METHOD_CALL                                         !6, 'setAccessible'
         38        SEND_VAL_EX                                              <true>
         39        DO_FCALL                                      0          
   59    40        INIT_METHOD_CALL                                         !7, 'setAccessible'
         41        SEND_VAL_EX                                              <true>
         42        DO_FCALL                                      0          
   60    43        ASSIGN                                                   !1, <array>
   61    44        NEW                                              $34     'A'
         45        DO_FCALL                                      0          
         46        ASSIGN                                                   !2, $34
   62    47        ASSIGN                                                   !4, 0
         48      > JMP                                                      ->68
   63    49    >   INIT_METHOD_CALL                                         !5, 'setValue'
         50        SEND_VAR_EX                                              !2
         51        CHECK_FUNC_ARG                                           
         52        FETCH_DIM_FUNC_ARG                               $38     !1, 'a'
         53        SEND_FUNC_ARG                                            $38
         54        DO_FCALL                                      0          
   64    55        INIT_METHOD_CALL                                         !6, 'setValue'
         56        SEND_VAR_EX                                              !2
         57        CHECK_FUNC_ARG                                           
         58        FETCH_DIM_FUNC_ARG                               $40     !1, 'b'
         59        SEND_FUNC_ARG                                            $40
         60        DO_FCALL                                      0          
   65    61        INIT_METHOD_CALL                                         !7, 'setValue'
         62        SEND_VAR_EX                                              !2
         63        CHECK_FUNC_ARG                                           
         64        FETCH_DIM_FUNC_ARG                               $42     !1, 'c'
         65        SEND_FUNC_ARG                                            $42
         66        DO_FCALL                                      0          
   62    67        PRE_INC                                                  !4
         68    >   IS_SMALLER                                               !4, !0
         69      > JMPNZ                                                    ~45, ->49
   66    70    > > RETURN                                                   1

Class Foo: [no user functions]
Class FooSelfHydratingProxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cTtZJ
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E > > RETURN                                                   null

End of function __construct

Function hydrate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cTtZJ
function name:  hydrate
number of ops:  12
compiled vars:  !0 = $data, !1 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        FETCH_DIM_R                                      ~3      !0, 'foo'
          3        ASSIGN_OBJ                                               !1, 'foo'
          4        OP_DATA                                                  ~3
   23     5        FETCH_DIM_R                                      ~5      !0, 'bar'
          6        ASSIGN_OBJ                                               !1, 'bar'
          7        OP_DATA                                                  ~5
   24     8        FETCH_DIM_R                                      ~7      !0, 'baz'
          9        ASSIGN_OBJ                                               !1, 'baz'
         10        OP_DATA                                                  ~7
   25    11      > RETURN                                                   null

End of function hydrate

Function extract:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cTtZJ
function name:  extract
number of ops:  9
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        FETCH_OBJ_R                                      ~1      !0, 'foo'
          2        INIT_ARRAY                                       ~2      ~1, 'foo'
          3        FETCH_OBJ_R                                      ~3      !0, 'bar'
          4        ADD_ARRAY_ELEMENT                                ~2      ~3, 'bar'
          5        FETCH_OBJ_R                                      ~4      !0, 'baz'
          6        ADD_ARRAY_ELEMENT                                ~2      ~4, 'baz'
          7      > RETURN                                                   ~2
   32     8*     > RETURN                                                   null

End of function extract

End of class FooSelfHydratingProxy.

Class A: [no user functions]
Class AHydrator:
Function hydrate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cTtZJ
function name:  hydrate
number of ops:  12
compiled vars:  !0 = $a, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        FETCH_DIM_R                                      ~3      !1, 'a'
          3        ASSIGN_OBJ                                               !0, 'a'
          4        OP_DATA                                                  ~3
   41     5        FETCH_DIM_R                                      ~5      !1, 'b'
          6        ASSIGN_OBJ                                               !0, 'b'
          7        OP_DATA                                                  ~5
   42     8        FETCH_DIM_R                                      ~7      !1, 'c'
          9        ASSIGN_OBJ                                               !0, 'c'
         10        OP_DATA                                                  ~7
   43    11      > RETURN                                                   null

End of function hydrate

End of class AHydrator.

Class A: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.84 ms | 1403 KiB | 13 Q