3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements \JsonSerializable { public $prop; public function jsonSerialize() { $obj = new stdClass; if ($this->prop) { $obj->prop = $this->prop; } return $obj; } } class B implements \JsonSerializable { public $a; public function jsonSerialize() { $obj = new stdClass; if ($this->a) { $obj->a = $this->a; } return $obj; } } $a = new A; $b = new B; $b->a = $a; var_dump(json_encode($b));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0vT33
function name:  (null)
number of ops:  17
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'a'
   19     1        DECLARE_CLASS                                            'b'
   35     2        NEW                                              $2      'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   36     5        NEW                                              $5      'B'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   37     8        ASSIGN_OBJ                                               !1, 'a'
          9        OP_DATA                                                  !0
   39    10        INIT_FCALL                                               'var_dump'
         11        INIT_FCALL                                               'json_encode'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Class A:
Function jsonserialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/0vT33
function name:  jsonSerialize
number of ops:  10
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   NEW                                              $1      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   11     3        FETCH_OBJ_R                                      ~4      'prop'
          4      > JMPZ                                                     ~4, ->8
   12     5    >   FETCH_OBJ_R                                      ~6      'prop'
          6        ASSIGN_OBJ                                               !0, 'prop'
          7        OP_DATA                                                  ~6
   15     8    > > RETURN                                                   !0
   16     9*     > RETURN                                                   null

End of function jsonserialize

End of class A.

Class B:
Function jsonserialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/0vT33
function name:  jsonSerialize
number of ops:  10
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $1      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   27     3        FETCH_OBJ_R                                      ~4      'a'
          4      > JMPZ                                                     ~4, ->8
   28     5    >   FETCH_OBJ_R                                      ~6      'a'
          6        ASSIGN_OBJ                                               !0, 'a'
          7        OP_DATA                                                  ~6
   31     8    > > RETURN                                                   !0
   32     9*     > RETURN                                                   null

End of function jsonserialize

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.45 ms | 1004 KiB | 15 Q