3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @psalm-param class-string|object $classOrObject */ function isInternalClass($classOrObject): bool { return (new ReflectionClass($classOrObject))->isInternal(); } /** * @return array<string, mixed> */ function objectToArray(object $object): array { return isInternalClass($object) ? get_object_vars($object) : (fn (): array => get_object_vars($this))->call($object); } final class A { private $a = 'incapsulated string'; } // user-defined class instance var_dump(objectToArray(new A())); // internal stdClass instance $object = new stdClass(); $object->a = 1; var_dump(objectToArray($object)); // internal DateTimeImmutable class instance var_dump(objectToArray(new DateTimeImmutable()));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2mtXC
function name:  (null)
number of ops:  28
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'objecttoarray'
          2        NEW                                              $1      'A'
          3        DO_FCALL                                      0          
          4        SEND_VAR                                                 $1
          5        DO_FCALL                                      0  $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                                 
   30     8        NEW                                              $5      'stdClass'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $5
   31    11        ASSIGN_OBJ                                               !0, 'a'
         12        OP_DATA                                                  1
   32    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'objecttoarray'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $9      
         17        SEND_VAR                                                 $9
         18        DO_ICALL                                                 
   35    19        INIT_FCALL                                               'var_dump'
         20        INIT_FCALL                                               'objecttoarray'
         21        NEW                                              $11     'DateTimeImmutable'
         22        DO_FCALL                                      0          
         23        SEND_VAR                                                 $11
         24        DO_FCALL                                      0  $13     
         25        SEND_VAR                                                 $13
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Function isinternalclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2mtXC
function name:  isInternalClass
number of ops:  10
compiled vars:  !0 = $classOrObject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        NEW                                              $1      'ReflectionClass'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $1, 'isInternal'
          5        DO_FCALL                                      0  $3      
          6        VERIFY_RETURN_TYPE                                       $3
          7      > RETURN                                                   $3
    9     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function isinternalclass

Function objecttoarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2mtXC
function name:  objectToArray
number of ops:  19
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'isinternalclass'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4      > JMPZ                                                     $1, ->10
   17     5    >   INIT_FCALL                                               'get_object_vars'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $2      
          8        QM_ASSIGN                                        ~3      $2
          9      > JMP                                                      ->15
   18    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2mtXC%3A18%240'
         11        INIT_METHOD_CALL                                         ~4, 'call'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $5      
         14        QM_ASSIGN                                        ~3      $5
         15    >   VERIFY_RETURN_TYPE                                       ~3
         16      > RETURN                                                   ~3
   19    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function objecttoarray

Function %00%7Bclosure%7D%2Fin%2F2mtXC%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2mtXC
function name:  {closure}
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
          6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2mtXC%3A18%240

Class A: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.03 ms | 1403 KiB | 21 Q