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 getTest() { return $this->test; } public function getTest2() { return $this->test2; } 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($recursionDepth = 2) { $entity = $this; $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/bBdDT
function name:  (null)
number of ops:  9
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   73     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/bBdDT
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 gettest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bBdDT
function name:  getTest
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                      ~0      'test'
          1      > RETURN                                                   ~0
   24     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/bBdDT
function name:  getTest2
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      'test2'
          1      > RETURN                                                   ~0
   29     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 = 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/bBdDT
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
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_THIS                                       ~4      
          1        ASSIGN                                                   !0, ~4
   34     2        NEW                                              $6      'ReflectionClass'
          3        GET_CLASS                                        ~7      !0
          4        SEND_VAL_EX                                              ~7
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $6
   35     7        ASSIGN                                                   !2, <array>
   36     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
   37    12    >   INIT_METHOD_CALL                                         !3, 'setAccessible'
         13        SEND_VAL_EX                                              <true>
         14        DO_FCALL                                      0          
   38    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
   39    22        INIT_METHOD_CALL                                         !3, 'setAccessible'
         23        SEND_VAL_EX                                              <false>
         24        DO_FCALL                                      0          
   36    25      > JMP                                                      ->11
         26    >   FE_FREE                                                  $12
   41    27      > RETURN                                                   !2
   42    28*     > RETURN                                                   null

End of function dismount

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

End of function entity2array

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.19 ms | 1408 KiB | 21 Q