3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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)) { foreach ((new ReflectionClass($this))->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { if (!$property->isStatic()) { $this->columns[] = $property->getName(); } } 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/IA37E
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
-------------------------------------------------------------------------------------
   43     0  E >   ASSIGN                                                   !0, <array>
   47     1        ASSIGN                                                   !1, 100000
   48     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !2, $10
   49     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->24
   50     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
   51    14        INIT_METHOD_CALL                                         !4, 'toArray'
         15        DO_FCALL                                      0  $16     
         16        ASSIGN                                                   !5, $16
   52    17        IS_NOT_IDENTICAL                                         !5, !0
         18      > JMPZ                                                     ~18, ->23
   53    19    >   NEW                                              $19     'Exception'
         20        SEND_VAL_EX                                              'Not+same'
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $19
   49    23    >   PRE_INC                                                  !3
         24    >   IS_SMALLER                                               !3, !1
         25      > JMPNZ                                                    ~22, ->8
   56    26    >   INIT_FCALL                                               'microtime'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $23     
         29        ASSIGN                                                   !6, $23
   57    30        INIT_FCALL                                               'memory_get_peak_usage'
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $25     
         33        ASSIGN                                                   !7, $25
   58    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

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IA37E
function name:  __construct
number of ops:  12
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   11     3        ASSIGN_OBJ                                               'a'
          4        OP_DATA                                                  !0
   12     5        ASSIGN_OBJ                                               'b'
          6        OP_DATA                                                  !1
   13     7        ASSIGN_OBJ                                               'c'
          8        OP_DATA                                                  !2
   15     9        INIT_METHOD_CALL                                         'setupColumns'
         10        DO_FCALL                                      0          
   16    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/IA37E
function name:  toArray
number of ops:  11
compiled vars:  !0 = $ret, !1 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   20     1        FETCH_OBJ_R                                      ~3      'columns'
          2      > FE_RESET_R                                       $4      ~3, ->8
          3    > > FE_FETCH_R                                               $4, !1, ->8
   21     4    >   FETCH_OBJ_R                                      ~6      !1
          5        ASSIGN_DIM                                               !0, !1
          6        OP_DATA                                                  ~6
   20     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   23     9      > RETURN                                                   !0
   24    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 = 32
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IA37E
function name:  setupColumns
number of ops:  37
compiled vars:  !0 = $class, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_THIS                                       ~2      
          1        GET_CLASS                                        ~3      ~2
          2        ASSIGN                                                   !0, ~3
   30     3        FETCH_STATIC_PROP_R          unknown             ~5      'columnRegistry'
          4        ARRAY_KEY_EXISTS                                 ~6      !0, ~5
          5        BOOL_NOT                                         ~7      ~6
          6      > JMPZ                                                     ~7, ->32
   31     7    >   NEW                                              $8      'ReflectionClass'
          8        FETCH_THIS                                       $9      
          9        SEND_VAR_EX                                              $9
         10        DO_FCALL                                      0          
         11        INIT_METHOD_CALL                                         $8, 'getProperties'
         12        SEND_VAL_EX                                              1
         13        DO_FCALL                                      0  $11     
         14      > FE_RESET_R                                       $12     $11, ->26
         15    > > FE_FETCH_R                                               $12, !1, ->26
   32    16    >   INIT_METHOD_CALL                                         !1, 'isStatic'
         17        DO_FCALL                                      0  $13     
         18        BOOL_NOT                                         ~14     $13
         19      > JMPZ                                                     ~14, ->25
   33    20    >   INIT_METHOD_CALL                                         !1, 'getName'
         21        DO_FCALL                                      0  $17     
         22        FETCH_OBJ_W                                      $15     'columns'
         23        ASSIGN_DIM                                               $15
         24        OP_DATA                                                  $17
   31    25    > > JMP                                                      ->15
         26    >   FE_FREE                                                  $12
   36    27        FETCH_OBJ_R                                      ~20     'columns'
         28        FETCH_STATIC_PROP_W          unknown             $18     'columnRegistry'
         29        ASSIGN_DIM                                               $18, !0
         30        OP_DATA                                                  ~20
         31      > JMP                                                      ->36
   38    32    >   FETCH_STATIC_PROP_R          unknown             ~22     'columnRegistry'
         33        FETCH_DIM_R                                      ~23     ~22, !0
         34        ASSIGN_OBJ                                               'columns'
         35        OP_DATA                                                  ~23
   40    36    > > RETURN                                                   null

End of function setupcolumns

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.7 ms | 1404 KiB | 19 Q