3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyError implements \JsonSerializable { private $name; private $code; private $msg; public function __construct($errorName, $errorCode, $errorMSG) { $this->name = $errorName; $this->code = $errorCode; $this->msg = $errorMSG; } public function jsonSerialize() { return get_object_vars($this); // or return [ 'name' => $this->name, 'code' => $this->code, 'msg' => $this->msg ]; } } $error = new MyError("Page not found", 404, "Unfortunately, the page does not exist"); echo json_encode($error);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b9g9h
function name:  (null)
number of ops:  12
compiled vars:  !0 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'myerror'
   26     1        NEW                                              $1      'MyError'
          2        SEND_VAL_EX                                              'Page+not+found'
          3        SEND_VAL_EX                                              404
          4        SEND_VAL_EX                                              'Unfortunately%2C+the+page+does+not+exist'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $1
   27     7        INIT_FCALL                                               'json_encode'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $4      
         10        ECHO                                                     $4
         11      > RETURN                                                   1

Class MyError:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b9g9h
function name:  __construct
number of ops:  10
compiled vars:  !0 = $errorName, !1 = $errorCode, !2 = $errorMSG
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        ASSIGN_OBJ                                               'name'
          4        OP_DATA                                                  !0
   11     5        ASSIGN_OBJ                                               'code'
          6        OP_DATA                                                  !1
   12     7        ASSIGN_OBJ                                               'msg'
          8        OP_DATA                                                  !2
   13     9      > 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/b9g9h
function name:  jsonSerialize
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   20     5*       FETCH_OBJ_R                                      ~2      'name'
          6*       INIT_ARRAY                                       ~3      ~2, 'name'
   21     7*       FETCH_OBJ_R                                      ~4      'code'
          8*       ADD_ARRAY_ELEMENT                                ~3      ~4, 'code'
   22     9*       FETCH_OBJ_R                                      ~5      'msg'
         10*       ADD_ARRAY_ELEMENT                                ~3      ~5, 'msg'
         11*       RETURN                                                   ~3
   24    12*     > RETURN                                                   null

End of function jsonserialize

End of class MyError.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.45 ms | 1465 KiB | 15 Q