3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ArraySerializableInterface {} class Bar { private $event = 'test'; public function dismount() { $object = $this; $reflectionClass = new \ReflectionClass(get_class($object)); $array =[]; foreach ($reflectionClass->getProperties() as $property) { $property->setAccessible(true); $value = $property->getValue($object); if (is_array($value)) { foreach ($value as $name => $foo) { if ($foo instanceof ArraySerializableInterface) { $array[$property->getName()][] = $foo->dismount(); } } continue; } $array[$property->getName()] = $property->getValue($object); $property->setAccessible(false); } return $array; } } class Foo { private $test = 'sd'; private $test2; /** * Constructor. */ public function __construct() { $this->test2 = [ new Bar(), new Bar(), new Bar(), new Bar(), ]; } public function getTest() { return $this->test; } public function getTest2() { return $this->test2; } public function dismount() { $object = $this; $reflectionClass = new \ReflectionClass(get_class($object)); $array =[]; foreach ($reflectionClass->getProperties() as $property) { $property->setAccessible(true); $value = $property->getValue($object); if (is_array($value)) { foreach ($value as $name => $foo) { if ($foo instanceof ArraySerializableInterface) { $array[$property->getName()][] = $foo->dismount(); } } continue; } $array[$property->getName()] = $value; $property->setAccessible(false); } return $array; } } $foo = new Foo; print_r( $foo->dismount());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1IumG
function name:  (null)
number of ops:  9
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   87     3        INIT_FCALL                                               'print_r'
          4        INIT_METHOD_CALL                                         !0, 'dismount'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Class ArraySerializableInterface: [no user functions]
Class Bar:
Function dismount:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 47
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 47
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 36
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 34
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 34
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/1IumG
function name:  dismount
number of ops:  50
compiled vars:  !0 = $object, !1 = $reflectionClass, !2 = $array, !3 = $property, !4 = $value, !5 = $foo, !6 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   FETCH_THIS                                       ~7      
          1        ASSIGN                                                   !0, ~7
   10     2        NEW                                              $9      'ReflectionClass'
          3        GET_CLASS                                        ~10     !0
          4        SEND_VAL_EX                                              ~10
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $9
   11     7        ASSIGN                                                   !2, <array>
   12     8        INIT_METHOD_CALL                                         !1, 'getProperties'
          9        DO_FCALL                                      0  $14     
         10      > FE_RESET_R                                       $15     $14, ->47
         11    > > FE_FETCH_R                                               $15, !3, ->47
   13    12    >   INIT_METHOD_CALL                                         !3, 'setAccessible'
         13        SEND_VAL_EX                                              <true>
         14        DO_FCALL                                      0          
   14    15        INIT_METHOD_CALL                                         !3, 'getValue'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $17     
         18        ASSIGN                                                   !4, $17
   15    19        TYPE_CHECK                                  128          !4
         20      > JMPZ                                                     ~19, ->36
   16    21    > > FE_RESET_R                                       $20     !4, ->34
         22    > > FE_FETCH_R                                       ~21     $20, !5, ->34
         23    >   ASSIGN                                                   !6, ~21
   17    24        INSTANCEOF                                               !5, 'ArraySerializableInterface'
         25      > JMPZ                                                     ~23, ->33
   18    26    >   INIT_METHOD_CALL                                         !3, 'getName'
         27        DO_FCALL                                      0  $24     
         28        INIT_METHOD_CALL                                         !5, 'dismount'
         29        DO_FCALL                                      0  $27     
         30        FETCH_DIM_W                                      $25     !2, $24
         31        ASSIGN_DIM                                               $25
         32        OP_DATA                                                  $27
   16    33    > > JMP                                                      ->22
         34    >   FE_FREE                                                  $20
   21    35      > JMP                                                      ->11
   23    36    >   INIT_METHOD_CALL                                         !3, 'getName'
         37        DO_FCALL                                      0  $28     
         38        INIT_METHOD_CALL                                         !3, 'getValue'
         39        SEND_VAR_EX                                              !0
         40        DO_FCALL                                      0  $30     
         41        ASSIGN_DIM                                               !2, $28
         42        OP_DATA                                                  $30
   24    43        INIT_METHOD_CALL                                         !3, 'setAccessible'
         44        SEND_VAL_EX                                              <false>
         45        DO_FCALL                                      0          
   12    46      > JMP                                                      ->11
         47    >   FE_FREE                                                  $15
   27    48      > RETURN                                                   !2
   28    49*     > RETURN                                                   null

End of function dismount

End of class Bar.

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1IumG
function name:  __construct
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   NEW                                              $1      'Bar'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~3      $1
   42     3        NEW                                              $4      'Bar'
          4        DO_FCALL                                      0          
          5        ADD_ARRAY_ELEMENT                                ~3      $4
   43     6        NEW                                              $6      'Bar'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~3      $6
   44     9        NEW                                              $8      'Bar'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~3      $8
   40    12        ASSIGN_OBJ                                               'test2'
   44    13        OP_DATA                                                  ~3
   46    14      > RETURN                                                   null

End of function __construct

Function gettest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1IumG
function name:  getTest
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   FETCH_OBJ_R                                      ~0      'test'
          1      > RETURN                                                   ~0
   51     2*     > RETURN                                                   null

End of function gettest

Function gettest2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1IumG
function name:  getTest2
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'test2'
          1      > RETURN                                                   ~0
   56     2*     > RETURN                                                   null

End of function gettest2

Function dismount:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 44
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 44
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 36
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 34
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 34
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/1IumG
function name:  dismount
number of ops:  47
compiled vars:  !0 = $object, !1 = $reflectionClass, !2 = $array, !3 = $property, !4 = $value, !5 = $foo, !6 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   FETCH_THIS                                       ~7      
          1        ASSIGN                                                   !0, ~7
   62     2        NEW                                              $9      'ReflectionClass'
          3        GET_CLASS                                        ~10     !0
          4        SEND_VAL_EX                                              ~10
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $9
   63     7        ASSIGN                                                   !2, <array>
   64     8        INIT_METHOD_CALL                                         !1, 'getProperties'
          9        DO_FCALL                                      0  $14     
         10      > FE_RESET_R                                       $15     $14, ->44
         11    > > FE_FETCH_R                                               $15, !3, ->44
   65    12    >   INIT_METHOD_CALL                                         !3, 'setAccessible'
         13        SEND_VAL_EX                                              <true>
         14        DO_FCALL                                      0          
   66    15        INIT_METHOD_CALL                                         !3, 'getValue'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $17     
         18        ASSIGN                                                   !4, $17
   67    19        TYPE_CHECK                                  128          !4
         20      > JMPZ                                                     ~19, ->36
   68    21    > > FE_RESET_R                                       $20     !4, ->34
         22    > > FE_FETCH_R                                       ~21     $20, !5, ->34
         23    >   ASSIGN                                                   !6, ~21
   69    24        INSTANCEOF                                               !5, 'ArraySerializableInterface'
         25      > JMPZ                                                     ~23, ->33
   70    26    >   INIT_METHOD_CALL                                         !3, 'getName'
         27        DO_FCALL                                      0  $24     
         28        INIT_METHOD_CALL                                         !5, 'dismount'
         29        DO_FCALL                                      0  $27     
         30        FETCH_DIM_W                                      $25     !2, $24
         31        ASSIGN_DIM                                               $25
         32        OP_DATA                                                  $27
   68    33    > > JMP                                                      ->22
         34    >   FE_FREE                                                  $20
   73    35      > JMP                                                      ->11
   75    36    >   INIT_METHOD_CALL                                         !3, 'getName'
         37        DO_FCALL                                      0  $28     
         38        ASSIGN_DIM                                               !2, $28
         39        OP_DATA                                                  !4
   76    40        INIT_METHOD_CALL                                         !3, 'setAccessible'
         41        SEND_VAL_EX                                              <false>
         42        DO_FCALL                                      0          
   64    43      > JMP                                                      ->11
         44    >   FE_FREE                                                  $15
   79    45      > RETURN                                                   !2
   80    46*     > RETURN                                                   null

End of function dismount

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.96 ms | 1408 KiB | 15 Q