3v4l.org

run code in 500+ PHP versions simultaneously
<?php enum MyEnum: string { case FOO = 'FOO'; } enum MyEnumWithJson: string implements \JsonSerializable { case FOO = 'FOO'; public function jsonSerialize(): mixed { return $this->value . '[jsonSerialize]'; } } $myEnum = MyEnum::FOO; echo json_encode($myEnum); var_dump([ 'isObject' => is_object($myEnum), 'isJsonSerializable' => $myEnum instanceof JsonSerializable, ]); echo "\n"; $myEnumWithJson = MyEnumWithJson::FOO; echo json_encode($myEnumWithJson); var_dump([ 'isObject' => is_object($myEnumWithJson), 'isJsonSerializable' => $myEnumWithJson instanceof JsonSerializable, ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OZb1n
function name:  (null)
number of ops:  30
compiled vars:  !0 = $myEnum, !1 = $myEnumWithJson
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'myenum'
    9     1        DECLARE_CLASS                                                'myenumwithjson'
   19     2        FETCH_CLASS_CONSTANT                                 ~2      'MyEnum', 'FOO'
          3        ASSIGN                                                       !0, ~2
   21     4        INIT_FCALL                                                   'json_encode'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $4      
          7        ECHO                                                         $4
   22     8        INIT_FCALL                                                   'var_dump'
   23     9        TYPE_CHECK                                      256  ~5      !0
         10        INIT_ARRAY                                           ~6      ~5, 'isObject'
   24    11        INSTANCEOF                                           ~7      !0, 'JsonSerializable'
         12        ADD_ARRAY_ELEMENT                                    ~6      ~7, 'isJsonSerializable'
         13        SEND_VAL                                                     ~6
   22    14        DO_ICALL                                                     
   27    15        ECHO                                                         '%0A'
   29    16        FETCH_CLASS_CONSTANT                                 ~9      'MyEnumWithJson', 'FOO'
         17        ASSIGN                                                       !1, ~9
   31    18        INIT_FCALL                                                   'json_encode'
         19        SEND_VAR                                                     !1
         20        DO_ICALL                                             $11     
         21        ECHO                                                         $11
   32    22        INIT_FCALL                                                   'var_dump'
   33    23        TYPE_CHECK                                      256  ~12     !1
         24        INIT_ARRAY                                           ~13     ~12, 'isObject'
   34    25        INSTANCEOF                                           ~14     !1, 'JsonSerializable'
         26        ADD_ARRAY_ELEMENT                                    ~13     ~14, 'isJsonSerializable'
         27        SEND_VAL                                                     ~13
   32    28        DO_ICALL                                                     
   35    29      > RETURN                                                       1

Class MyEnum: [no user functions]
Class MyEnumWithJson:
Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OZb1n
function name:  jsonSerialize
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                          ~0      'value'
          1        CONCAT                                               ~1      ~0, '%5BjsonSerialize%5D'
          2      > RETURN                                                       ~1
   16     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function jsonserialize

End of class MyEnumWithJson.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
155.81 ms | 771 KiB | 10 Q