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; $start = microtime(true); for($i = 0; $i < $numReps; $i++) { $o = new A(1, 2, 3); $res = $o->toArray(); if ($res !== $expected) { throw new Exception("Not same"); } } $end = microtime(true); $mem = memory_get_peak_usage(true); echo number_format($end-$start, 8) . "\t$mem\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 8
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 8
Branch analysis from position: 26
Branch analysis from position: 8
filename:       /in/rhljP
function name:  (null)
number of ops:  45
compiled vars:  !0 = $expected, !1 = $numReps, !2 = $start, !3 = $i, !4 = $o, !5 = $res, !6 = $end, !7 = $mem
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ASSIGN                                                   !0, <array>
   46     1        ASSIGN                                                   !1, 100000
   47     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !2, $10
   48     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->24
   49     8    >   NEW                                              $13     'A'
          9        SEND_VAL_EX                                              1
         10        SEND_VAL_EX                                              2
         11        SEND_VAL_EX                                              3
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !4, $13
   50    14        INIT_METHOD_CALL                                         !4, 'toArray'
         15        DO_FCALL                                      0  $16     
         16        ASSIGN                                                   !5, $16
   51    17        IS_NOT_IDENTICAL                                         !5, !0
         18      > JMPZ                                                     ~18, ->23
   52    19    >   NEW                                              $19     'Exception'
         20        SEND_VAL_EX                                              'Not+same'
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $19
   48    23    >   PRE_INC                                                  !3
         24    >   IS_SMALLER                                               !3, !1
         25      > JMPNZ                                                    ~22, ->8
   55    26    >   INIT_FCALL                                               'microtime'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $23     
         29        ASSIGN                                                   !6, $23
   56    30        INIT_FCALL                                               'memory_get_peak_usage'
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $25     
         33        ASSIGN                                                   !7, $25
   57    34        INIT_FCALL                                               'number_format'
         35        SUB                                              ~27     !6, !2
         36        SEND_VAL                                                 ~27
         37        SEND_VAL                                                 8
         38        DO_ICALL                                         $28     
         39        ROPE_INIT                                     3  ~30     '%09'
         40        ROPE_ADD                                      1  ~30     ~30, !7
         41        ROPE_END                                      2  ~29     ~30, '%0A'
         42        CONCAT                                           ~32     $28, ~29
         43        ECHO                                                     ~32
         44      > RETURN                                                   1

Function x:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rhljP
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/rhljP
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/rhljP
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/rhljP
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:
165.52 ms | 1411 KiB | 24 Q