3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomeObject implements JsonSerializable { public string $placeholder = 'hallo'; public string $id; public string $model; public string $value; public bool $disabled; public bool $required; public function jsonSerialize(): mixed { return array_map( fn($value) => $value ?? '', array_merge( get_class_vars(__CLASS__), get_object_vars($this) ) ); } } class MainObject implements JsonSerializable { public string $mainName; public SomeObject $someObject; public function __construct() { $this->mainName = (new ReflectionClass(MainObject::class))->getShortName(); $this->someObject = new SomeObject(); } public function jsonSerialize(): mixed { return get_object_vars($this); } } $main = new MainObject; echo json_encode($main, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mm8Ss
function name:  (null)
number of ops:  11
compiled vars:  !0 = $main
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'someobject'
   23     1        DECLARE_CLASS                                            'mainobject'
   39     2        NEW                                              $1      'MainObject'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   40     5        INIT_FCALL                                               'json_encode'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 128
          8        DO_ICALL                                         $4      
          9        ECHO                                                     $4
         10      > RETURN                                                   1

Class SomeObject:
Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mm8Ss
function name:  jsonSerialize
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'array_map'
   14     1        DECLARE_LAMBDA_FUNCTION                          ~0      [0]
          2        SEND_VAL                                                 ~0
   15     3        INIT_FCALL                                               'array_merge'
   16     4        INIT_FCALL                                               'get_class_vars'
          5        SEND_VAL                                                 'SomeObject'
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
   17     8        INIT_FCALL                                               'get_object_vars'
          9        FETCH_THIS                                       ~2      
         10        SEND_VAL                                                 ~2
         11        DO_ICALL                                         $3      
         12        SEND_VAR                                                 $3
   15    13        DO_ICALL                                         $4      
   17    14        SEND_VAR                                                 $4
   13    15        DO_ICALL                                         $5      
   17    16      > RETURN                                                   $5
   20    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mm8Ss
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        COALESCE                                         ~1      !0
          2        QM_ASSIGN                                        ~1      ''
          3      > RETURN                                                   ~1
          4*     > RETURN                                                   null

End of Dynamic Function 0

End of function jsonserialize

End of class SomeObject.

Class MainObject:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mm8Ss
function name:  __construct
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $1      'ReflectionClass'
          1        SEND_VAL_EX                                              'MainObject'
          2        DO_FCALL                                      0          
          3        INIT_METHOD_CALL                                         $1, 'getShortName'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_OBJ                                               'mainName'
          6        OP_DATA                                                  $3
   30     7        NEW                                              $5      'SomeObject'
          8        DO_FCALL                                      0          
          9        ASSIGN_OBJ                                               'someObject'
         10        OP_DATA                                                  $5
   31    11      > RETURN                                                   null

End of function __construct

Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mm8Ss
function name:  jsonSerialize
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   36     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function jsonserialize

End of class MainObject.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.95 ms | 1009 KiB | 18 Q