3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myClass { public $item1 = 1; public $item2 = '中文'; function to_json() { //url编码,避免json_encode将中文转为unicode $this->item2 = urlencode($this->item2); $str_json = json_encode($this); //url解码,转完json后将各属性返回,确保对象属性不变 $this->item2 = urldecode($this->item2); return urldecode($str_json); } } $c = new myClass(); echo json_encode($c); echo '<br/>'; echo $c->to_json(); echo '<br/>'; echo json_encode($c); echo '<br/>'; echo json_encode('胥');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aW0f5
function name:  (null)
number of ops:  22
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $1      'myClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   17     3        INIT_FCALL                                               'json_encode'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        ECHO                                                     $4
   18     7        ECHO                                                     '%3Cbr%2F%3E'
   19     8        INIT_METHOD_CALL                                         !0, 'to_json'
          9        DO_FCALL                                      0  $5      
         10        ECHO                                                     $5
   20    11        ECHO                                                     '%3Cbr%2F%3E'
   21    12        INIT_FCALL                                               'json_encode'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $6      
         15        ECHO                                                     $6
   22    16        ECHO                                                     '%3Cbr%2F%3E'
   23    17        INIT_FCALL                                               'json_encode'
         18        SEND_VAL                                                 '%E8%83%A5'
         19        DO_ICALL                                         $7      
         20        ECHO                                                     $7
         21      > RETURN                                                   1

Class myClass:
Function to_json:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aW0f5
function name:  to_json
number of ops:  22
compiled vars:  !0 = $str_json
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'urlencode'
          1        FETCH_OBJ_R                                      ~2      'item2'
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4        ASSIGN_OBJ                                               'item2'
          5        OP_DATA                                                  $3
    9     6        INIT_FCALL                                               'json_encode'
          7        FETCH_THIS                                       ~4      
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !0, $5
   11    11        INIT_FCALL                                               'urldecode'
         12        FETCH_OBJ_R                                      ~8      'item2'
         13        SEND_VAL                                                 ~8
         14        DO_ICALL                                         $9      
         15        ASSIGN_OBJ                                               'item2'
         16        OP_DATA                                                  $9
   12    17        INIT_FCALL                                               'urldecode'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $10     
         20      > RETURN                                                   $10
   13    21*     > RETURN                                                   null

End of function to_json

End of class myClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.97 ms | 1405 KiB | 19 Q