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; 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/Lh0ka
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
-------------------------------------------------------------------------------------
   43     0  E >   ASSIGN                                                   !0, <array>
   47     1        ASSIGN                                                   !1, 100000
   48     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->20
   49     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
   50    10        INIT_METHOD_CALL                                         !3, 'toArray'
         11        DO_FCALL                                      0  $11     
         12        ASSIGN                                                   !4, $11
   51    13        IS_NOT_IDENTICAL                                         !4, !0
         14      > JMPZ                                                     ~13, ->19
   52    15    >   NEW                                              $14     'Exception'
         16        SEND_VAL_EX                                              'Not+same'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $14
   48    19    >   PRE_INC                                                  !2
         20    >   IS_SMALLER                                               !2, !1
         21      > JMPNZ                                                    ~17, ->4
   55    22    >   ECHO                                                     'OK'
         23      > RETURN                                                   1

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Lh0ka
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/Lh0ka
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/Lh0ka
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:
157.3 ms | 1407 KiB | 13 Q