3v4l.org

run code in 300+ PHP versions simultaneously
<?php function x($o) { return get_object_vars($o);} class A { public $a; public $b; private $c; protected static $columnRegistry = array(); protected $columns = array(); public function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; $this->setupColumns(); } public function toArray() { $ret = []; foreach ($this->columns as $column) { $ret[$column] = $this->$column; } return $ret; } protected function setupColumns() { $class = get_class($this); // Define columns for current row if (!array_key_exists($class, self::$columnRegistry)) { $this->columns = array_keys(x($this)); self::$columnRegistry[$class] = $this->columns; } else { $this->columns = self::$columnRegistry[$class]; } } } $expected = [ 'a' => 1, 'b' => 2, ]; $numReps = 100000; for($i = 0; $i < $numReps; $i++) { $o = new A(1, 2, 3); $res = $o->toArray(); if ($res !== $expected) { throw new Exception("Not same"); } } echo "OK";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 4
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 4
Branch analysis from position: 22
Branch analysis from position: 4
filename:       /in/aGchO
function name:  (null)
number of ops:  24
compiled vars:  !0 = $expected, !1 = $numReps, !2 = $i, !3 = $o, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ASSIGN                                                   !0, <array>
   46     1        ASSIGN                                                   !1, 100000
   47     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->20
   48     4    >   NEW                                              $8      'A'
          5        SEND_VAL_EX                                              1
          6        SEND_VAL_EX                                              2
          7        SEND_VAL_EX                                              3
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $8
   49    10        INIT_METHOD_CALL                                         !3, 'toArray'
         11        DO_FCALL                                      0  $11     
         12        ASSIGN                                                   !4, $11
   50    13        IS_NOT_IDENTICAL                                         !4, !0
         14      > JMPZ                                                     ~13, ->19
   51    15    >   NEW                                              $14     'Exception'
         16        SEND_VAL_EX                                              'Not+same'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $14
   47    19    >   PRE_INC                                                  !2
         20    >   IS_SMALLER                                               !2, !1
         21      > JMPNZ                                                    ~17, ->4
   54    22    >   ECHO                                                     'OK'
         23      > RETURN                                                   1

Function x:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aGchO
function name:  x
number of ops:  6
compiled vars:  !0 = $o
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'get_object_vars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of function x

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aGchO
function name:  __construct
number of ops:  12
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   13     3        ASSIGN_OBJ                                               'a'
          4        OP_DATA                                                  !0
   14     5        ASSIGN_OBJ                                               'b'
          6        OP_DATA                                                  !1
   15     7        ASSIGN_OBJ                                               'c'
          8        OP_DATA                                                  !2
   17     9        INIT_METHOD_CALL                                         'setupColumns'
         10        DO_FCALL                                      0          
   18    11      > RETURN                                                   null

End of function __construct

Function toarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/aGchO
function name:  toArray
number of ops:  11
compiled vars:  !0 = $ret, !1 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1        FETCH_OBJ_R                                      ~3      'columns'
          2      > FE_RESET_R                                       $4      ~3, ->8
          3    > > FE_FETCH_R                                               $4, !1, ->8
   23     4    >   FETCH_OBJ_R                                      ~6      !1
          5        ASSIGN_DIM                                               !0, !1
          6        OP_DATA                                                  ~6
   22     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   25     9      > RETURN                                                   !0
   26    10*     > RETURN                                                   null

End of function toarray

Function setupcolumns:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aGchO
function name:  setupColumns
number of ops:  26
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_THIS                                       ~1      
          1        GET_CLASS                                        ~2      ~1
          2        ASSIGN                                                   !0, ~2
   32     3        FETCH_STATIC_PROP_R          unknown             ~4      'columnRegistry'
          4        ARRAY_KEY_EXISTS                                 ~5      !0, ~4
          5        BOOL_NOT                                         ~6      ~5
          6      > JMPZ                                                     ~6, ->21
   33     7    >   INIT_FCALL                                               'array_keys'
          8        INIT_FCALL                                               'x'
          9        FETCH_THIS                                       ~8      
         10        SEND_VAL                                                 ~8
         11        DO_FCALL                                      0  $9      
         12        SEND_VAR                                                 $9
         13        DO_ICALL                                         $10     
         14        ASSIGN_OBJ                                               'columns'
         15        OP_DATA                                                  $10
   35    16        FETCH_OBJ_R                                      ~13     'columns'
         17        FETCH_STATIC_PROP_W          unknown             $11     'columnRegistry'
         18        ASSIGN_DIM                                               $11, !0
         19        OP_DATA                                                  ~13
         20      > JMP                                                      ->25
   37    21    >   FETCH_STATIC_PROP_R          unknown             ~15     'columnRegistry'
         22        FETCH_DIM_R                                      ~16     ~15, !0
         23        ASSIGN_OBJ                                               'columns'
         24        OP_DATA                                                  ~16
   39    25    > > RETURN                                                   null

End of function setupcolumns

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.48 ms | 1407 KiB | 18 Q