3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $test = 'sd'; private $test2; /** * Constructor. */ public function __construct() { $this->test2 = [ new \stdClass(), new \stdClass(), new \stdClass(), new \stdClass(), ]; } public function dismount() { $object = $this; $reflectionClass = new ReflectionClass(get_class($object)); $array = array(); foreach ($reflectionClass->getProperties() as $property) { $property->setAccessible(true); $array[$property->getName()] = $property->getValue($object); $property->setAccessible(false); } return $array; } public function entity2array($entity, $recursionDepth = 2) { $result = array(); $class = new ReflectionClass(get_class($entity)); foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { $methodName = $method->name; if (strpos($methodName, "get") === 0 && strlen($methodName) > 3) { $propertyName = lcfirst(substr($methodName, 3)); $value = $method->invoke($entity); if (is_object($value)) { if ($recursionDepth > 0) { $result[$propertyName] = $this->entity2array($value, $recursionDepth - 1); } else { $result[$propertyName] = "***"; //stop recursion } } else { $result[$propertyName] = $value; } } } return $result; } } $foo = new Foo; print_r( $foo->entity2array());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XLrs6
function name:  (null)
number of ops:  9
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   62     3        INIT_FCALL                                               'print_r'
          4        INIT_METHOD_CALL                                         !0, 'entity2array'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

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

End of function __construct

Function dismount:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 26
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/XLrs6
function name:  dismount
number of ops:  29
compiled vars:  !0 = $object, !1 = $reflectionClass, !2 = $array, !3 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   FETCH_THIS                                       ~4      
          1        ASSIGN                                                   !0, ~4
   24     2        NEW                                              $6      'ReflectionClass'
          3        GET_CLASS                                        ~7      !0
          4        SEND_VAL_EX                                              ~7
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $6
   25     7        ASSIGN                                                   !2, <array>
   26     8        INIT_METHOD_CALL                                         !1, 'getProperties'
          9        DO_FCALL                                      0  $11     
         10      > FE_RESET_R                                       $12     $11, ->26
         11    > > FE_FETCH_R                                               $12, !3, ->26
   27    12    >   INIT_METHOD_CALL                                         !3, 'setAccessible'
         13        SEND_VAL_EX                                              <true>
         14        DO_FCALL                                      0          
   28    15        INIT_METHOD_CALL                                         !3, 'getName'
         16        DO_FCALL                                      0  $14     
         17        INIT_METHOD_CALL                                         !3, 'getValue'
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $16     
         20        ASSIGN_DIM                                               !2, $14
         21        OP_DATA                                                  $16
   29    22        INIT_METHOD_CALL                                         !3, 'setAccessible'
         23        SEND_VAL_EX                                              <false>
         24        DO_FCALL                                      0          
   26    25      > JMP                                                      ->11
         26    >   FE_FREE                                                  $12
   31    27      > RETURN                                                   !2
   32    28*     > RETURN                                                   null

End of function dismount

Function entity2array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 55
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 55
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 54
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 52
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 49
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 54
Branch analysis from position: 24
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
filename:       /in/XLrs6
function name:  entity2array
number of ops:  58
compiled vars:  !0 = $entity, !1 = $recursionDepth, !2 = $result, !3 = $class, !4 = $method, !5 = $methodName, !6 = $propertyName, !7 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
   35     2        ASSIGN                                                   !2, <array>
   36     3        NEW                                              $9      'ReflectionClass'
          4        GET_CLASS                                        ~10     !0
          5        SEND_VAL_EX                                              ~10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !3, $9
   37     8        INIT_METHOD_CALL                                         !3, 'getMethods'
          9        SEND_VAL_EX                                              1
         10        DO_FCALL                                      0  $13     
         11      > FE_RESET_R                                       $14     $13, ->55
         12    > > FE_FETCH_R                                               $14, !4, ->55
   38    13    >   FETCH_OBJ_R                                      ~15     !4, 'name'
         14        ASSIGN                                                   !5, ~15
   39    15        INIT_FCALL                                               'strpos'
         16        SEND_VAR                                                 !5
         17        SEND_VAL                                                 'get'
         18        DO_ICALL                                         $17     
         19        IS_IDENTICAL                                     ~18     $17, 0
         20      > JMPZ_EX                                          ~18     ~18, ->24
         21    >   STRLEN                                           ~19     !5
         22        IS_SMALLER                                       ~20     3, ~19
         23        BOOL                                             ~18     ~20
         24    > > JMPZ                                                     ~18, ->54
   40    25    >   INIT_FCALL                                               'lcfirst'
         26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !5
         28        SEND_VAL                                                 3
         29        DO_ICALL                                         $21     
         30        SEND_VAR                                                 $21
         31        DO_ICALL                                         $22     
         32        ASSIGN                                                   !6, $22
   41    33        INIT_METHOD_CALL                                         !4, 'invoke'
         34        SEND_VAR_EX                                              !0
         35        DO_FCALL                                      0  $24     
         36        ASSIGN                                                   !7, $24
   43    37        TYPE_CHECK                                  256          !7
         38      > JMPZ                                                     ~26, ->52
   44    39    >   IS_SMALLER                                               0, !1
         40      > JMPZ                                                     ~27, ->49
   45    41    >   INIT_METHOD_CALL                                         'entity2array'
         42        SEND_VAR_EX                                              !7
         43        SUB                                              ~29     !1, 1
         44        SEND_VAL_EX                                              ~29
         45        DO_FCALL                                      0  $30     
         46        ASSIGN_DIM                                               !2, !6
         47        OP_DATA                                                  $30
         48      > JMP                                                      ->51
   47    49    >   ASSIGN_DIM                                               !2, !6
         50        OP_DATA                                                  '%2A%2A%2A'
         51    > > JMP                                                      ->54
   50    52    >   ASSIGN_DIM                                               !2, !6
         53        OP_DATA                                                  !7
   37    54    > > JMP                                                      ->12
         55    >   FE_FREE                                                  $14
   54    56      > RETURN                                                   !2
   55    57*     > RETURN                                                   null

End of function entity2array

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.53 ms | 1408 KiB | 21 Q