3v4l.org

run code in 500+ PHP versions simultaneously
<?php class SomeClass implements JsonSerializable { public function jsonSerialize() { return [get_object_vars($this)]; } } $class = new SomeClass; var_dump(json_encode($class)); var_dump(json_last_error() == JSON_ERROR_RECURSION); $arr = [$class]; var_dump(json_encode($arr)); var_dump(json_last_error() == JSON_ERROR_RECURSION); class SomeOtherClass implements JsonSerializable { public function jsonSerialize() { return get_object_vars($this); } } $class = new SomeOtherClass; var_dump(json_encode($class)); var_dump(json_last_error() == JSON_ERROR_RECURSION); $arr = [$class]; var_dump(json_encode($arr)); var_dump(json_last_error() == JSON_ERROR_RECURSION);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OoR7D
function name:  (null)
number of ops:  61
compiled vars:  !0 = $class, !1 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'someclass'
    9     1        NEW                                                  $2      'SomeClass'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $2
   10     4        INIT_FCALL                                                   'var_dump'
          5        INIT_FCALL                                                   'json_encode'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $5      
          8        SEND_VAR                                                     $5
          9        DO_ICALL                                                     
   11    10        INIT_FCALL                                                   'var_dump'
         11        INIT_FCALL                                                   'json_last_error'
         12        DO_ICALL                                             $7      
         13        IS_EQUAL                                             ~8      $7, 6
         14        SEND_VAL                                                     ~8
         15        DO_ICALL                                                     
   13    16        INIT_ARRAY                                           ~10     !0
         17        ASSIGN                                                       !1, ~10
   14    18        INIT_FCALL                                                   'var_dump'
         19        INIT_FCALL                                                   'json_encode'
         20        SEND_VAR                                                     !1
         21        DO_ICALL                                             $12     
         22        SEND_VAR                                                     $12
         23        DO_ICALL                                                     
   15    24        INIT_FCALL                                                   'var_dump'
         25        INIT_FCALL                                                   'json_last_error'
         26        DO_ICALL                                             $14     
         27        IS_EQUAL                                             ~15     $14, 6
         28        SEND_VAL                                                     ~15
         29        DO_ICALL                                                     
   18    30        DECLARE_CLASS                                                'someotherclass'
   24    31        NEW                                                  $17     'SomeOtherClass'
         32        DO_FCALL                                          0          
         33        ASSIGN                                                       !0, $17
   25    34        INIT_FCALL                                                   'var_dump'
         35        INIT_FCALL                                                   'json_encode'
         36        SEND_VAR                                                     !0
         37        DO_ICALL                                             $20     
         38        SEND_VAR                                                     $20
         39        DO_ICALL                                                     
   26    40        INIT_FCALL                                                   'var_dump'
         41        INIT_FCALL                                                   'json_last_error'
         42        DO_ICALL                                             $22     
         43        IS_EQUAL                                             ~23     $22, 6
         44        SEND_VAL                                                     ~23
         45        DO_ICALL                                                     
   28    46        INIT_ARRAY                                           ~25     !0
         47        ASSIGN                                                       !1, ~25
   29    48        INIT_FCALL                                                   'var_dump'
         49        INIT_FCALL                                                   'json_encode'
         50        SEND_VAR                                                     !1
         51        DO_ICALL                                             $27     
         52        SEND_VAR                                                     $27
         53        DO_ICALL                                                     
   30    54        INIT_FCALL                                                   'var_dump'
         55        INIT_FCALL                                                   'json_last_error'
         56        DO_ICALL                                             $29     
         57        IS_EQUAL                                             ~30     $29, 6
         58        SEND_VAL                                                     ~30
         59        DO_ICALL                                                     
         60      > RETURN                                                       1

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

End of function jsonserialize

End of class SomeClass.

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

End of function jsonserialize

End of class SomeOtherClass.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
151.83 ms | 1914 KiB | 12 Q