3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ArraySerializableInterface {} class Baz { private $BazEvent = 'BazEvent'; } class Bar{ private $event = 'BarEvent'; private $secendClass; /** * Constructor. */ public function __construct() { $this->secendClass = [ new Baz(), ]; } } class Foo { /** * @var string */ private $providerId; /** * @var array */ private $events; /** * Constructor. */ public function __construct($providerId) { $this->providerId = $providerId; $this->events = []; } /** * @return string */ public function getProviderId() { return $this->providerId; } /** * @return array */ public function getEvents() { return $this->events; } /** * @param EventsInterface $events * * @return $this */ public function addEvents(EventsInterface $events) { $this->events[] = $events; return $this; } } 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('crm_newsletter'); var_dump( entity2array($foo));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EGCvk
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   NEW                                              $1      'Foo'
          1        SEND_VAL_EX                                              'crm_newsletter'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
  100     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'entity2array'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function entity2array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 56
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 56
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 = 55
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 53
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 50
Branch analysis from position: 41
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 = 12
Branch analysis from position: 12
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 = 12
Branch analysis from position: 12
Branch analysis from position: 55
Branch analysis from position: 24
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/EGCvk
function name:  entity2array
number of ops:  59
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
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
   77     2        ASSIGN                                                   !2, <array>
   78     3        NEW                                              $9      'ReflectionClass'
          4        GET_CLASS                                        ~10     !0
          5        SEND_VAL_EX                                              ~10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !3, $9
   79     8        INIT_METHOD_CALL                                         !3, 'getMethods'
          9        SEND_VAL_EX                                              1
         10        DO_FCALL                                      0  $13     
         11      > FE_RESET_R                                       $14     $13, ->56
         12    > > FE_FETCH_R                                               $14, !4, ->56
   80    13    >   FETCH_OBJ_R                                      ~15     !4, 'name'
         14        ASSIGN                                                   !5, ~15
   81    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, ->55
   82    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
   83    33        INIT_METHOD_CALL                                         !4, 'invoke'
         34        SEND_VAR_EX                                              !0
         35        DO_FCALL                                      0  $24     
         36        ASSIGN                                                   !7, $24
   85    37        TYPE_CHECK                                  256          !7
         38      > JMPZ                                                     ~26, ->53
   86    39    >   IS_SMALLER                                               0, !1
         40      > JMPZ                                                     ~27, ->50
   87    41    >   FETCH_THIS                                       $29     
         42        INIT_METHOD_CALL                                         $29, 'entity2array'
         43        SEND_VAR_EX                                              !7
         44        SUB                                              ~30     !1, 1
         45        SEND_VAL_EX                                              ~30
         46        DO_FCALL                                      0  $31     
         47        ASSIGN_DIM                                               !2, !6
         48        OP_DATA                                                  $31
         49      > JMP                                                      ->52
   89    50    >   ASSIGN_DIM                                               !2, !6
         51        OP_DATA                                                  '%2A%2A%2A'
         52    > > JMP                                                      ->55
   92    53    >   ASSIGN_DIM                                               !2, !6
         54        OP_DATA                                                  !7
   79    55    > > JMP                                                      ->12
         56    >   FE_FREE                                                  $14
   96    57      > RETURN                                                   !2
   97    58*     > RETURN                                                   null

End of function entity2array

Class ArraySerializableInterface: [no user functions]
Class Baz: [no user functions]
Class Bar:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EGCvk
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'Baz'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~3      $1
   19     3        ASSIGN_OBJ                                               'secendClass'
   20     4        OP_DATA                                                  ~3
   22     5      > RETURN                                                   null

End of function __construct

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/EGCvk
function name:  __construct
number of ops:  6
compiled vars:  !0 = $providerId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        ASSIGN_OBJ                                               'providerId'
          2        OP_DATA                                                  !0
   42     3        ASSIGN_OBJ                                               'events'
          4        OP_DATA                                                  <array>
   43     5      > RETURN                                                   null

End of function __construct

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

End of function getproviderid

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

End of function getevents

Function addevents:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EGCvk
function name:  addEvents
number of ops:  7
compiled vars:  !0 = $events
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   68     1        FETCH_OBJ_W                                      $1      'events'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   70     4        FETCH_THIS                                       ~3      
          5      > RETURN                                                   ~3
   71     6*     > RETURN                                                   null

End of function addevents

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.08 ms | 1407 KiB | 22 Q