3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (PHP_VERSION !== '7.2.0alpha2') die('Meh'); function test($label = '') { global $t; $t2 = microtime(1); if ($label) echo str_pad($label . ': ', 32, '.', STR_PAD_RIGHT) . ' ' . 1000 * ($t2 - $t) . 'ms' . "\n"; $t = $t2; } $c = 1; $c2 = 10000; // --------------------- class Meh { function hem() { return 1; } } class MehBag { public $meh1, $meh2, $meh3; function __construct(Meh $meh) { $this->meh1 = $meh; $this->meh2 = $meh; $this->meh3 = $meh; } } $x1 = function (Meh $meh1, Meh $meh2, Meh $meh3) { return $meh1->hem() + $meh2->hem() + $meh3->hem(); }; $x2 = function (MehBag $bag) { return $bag->meh1->hem() + $bag->meh2->hem() + $bag->meh3->hem(); }; // --------------------- test(); for ($i = $c; $i--;) { for ($j = $c2; $j--;) { $rc = new \ReflectionFunction($x1); $rp = $rc->getParameters(); $bag = [ Meh::class => new Meh() ]; $args = []; foreach ($rp as $p) { $pc = $p->getClass(); $name = $pc->name ?? null; if ($name) $args[] = $bag[$name]; } $result1 = $x1(...$args); } } test('ref'); for ($i = $c; $i--;) { for ($j = $c2; $j--;) { $bag = new MehBag(new Meh()); $result2 = $x2($bag); } } test('bag'); var_dump($result1); var_dump($result2);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 1, Position 2 = 2
Branch analysis from position: 1
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 12
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 55
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 57
Branch analysis from position: 69
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 57
Branch analysis from position: 69
Branch analysis from position: 57
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 14
Branch analysis from position: 48
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 40
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 40
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 39
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 14
Branch analysis from position: 48
Branch analysis from position: 14
Branch analysis from position: 40
filename:       /in/HJWvQ
function name:  (null)
number of ops:  81
compiled vars:  !0 = $c, !1 = $c2, !2 = $x1, !3 = $x2, !4 = $i, !5 = $j, !6 = $rc, !7 = $rp, !8 = $bag, !9 = $args, !10 = $p, !11 = $pc, !12 = $name, !13 = $result1, !14 = $result2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E > > JMPZ                                                     <true>, ->2
          1    > > EXIT                                                     'Meh'
   11     2    >   ASSIGN                                                   !0, 1
   12     3        ASSIGN                                                   !1, 10000
   30     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHJWvQ%3A30%240'
          5        ASSIGN                                                   !2, ~17
   34     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHJWvQ%3A34%241'
          7        ASSIGN                                                   !3, ~19
   43     8        INIT_FCALL                                               'test'
          9        DO_FCALL                                      0          
   45    10        ASSIGN                                                   !4, !0
         11      > JMP                                                      ->48
   46    12    >   ASSIGN                                                   !5, !1
         13      > JMP                                                      ->46
   47    14    >   NEW                                              $24     'ReflectionFunction'
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !6, $24
   48    18        INIT_METHOD_CALL                                         !6, 'getParameters'
         19        DO_FCALL                                      0  $27     
         20        ASSIGN                                                   !7, $27
   50    21        NEW                                              $29     'Meh'
         22        DO_FCALL                                      0          
         23        INIT_ARRAY                                       ~31     $29, 'Meh'
   49    24        ASSIGN                                                   !8, ~31
   52    25        ASSIGN                                                   !9, <array>
   53    26      > FE_RESET_R                                       $34     !7, ->40
         27    > > FE_FETCH_R                                               $34, !10, ->40
   54    28    >   INIT_METHOD_CALL                                         !10, 'getClass'
         29        DO_FCALL                                      0  $35     
         30        ASSIGN                                                   !11, $35
   55    31        FETCH_OBJ_IS                                     ~37     !11, 'name'
         32        COALESCE                                         ~38     ~37
         33        QM_ASSIGN                                        ~38     null
         34        ASSIGN                                                   !12, ~38
   56    35      > JMPZ                                                     !12, ->39
         36    >   FETCH_DIM_R                                      ~41     !8, !12
         37        ASSIGN_DIM                                               !9
         38        OP_DATA                                                  ~41
   53    39    > > JMP                                                      ->27
         40    >   FE_FREE                                                  $34
   58    41        INIT_DYNAMIC_CALL                                        !2
         42        SEND_UNPACK                                              !9
         43        CHECK_UNDEF_ARGS                                         
         44        DO_FCALL                                      1  $42     
         45        ASSIGN                                                   !13, $42
   46    46    >   POST_DEC                                         ~44     !5
         47      > JMPNZ                                                    ~44, ->14
   45    48    >   POST_DEC                                         ~45     !4
         49      > JMPNZ                                                    ~45, ->12
   61    50    >   INIT_FCALL                                               'test'
         51        SEND_VAL                                                 'ref'
         52        DO_FCALL                                      0          
   63    53        ASSIGN                                                   !4, !0
         54      > JMP                                                      ->69
   64    55    >   ASSIGN                                                   !5, !1
         56      > JMP                                                      ->67
   65    57    >   NEW                                              $49     'MehBag'
         58        NEW                                              $50     'Meh'
         59        DO_FCALL                                      0          
         60        SEND_VAR_NO_REF_EX                                       $50
         61        DO_FCALL                                      0          
         62        ASSIGN                                                   !8, $49
   66    63        INIT_DYNAMIC_CALL                                        !3
         64        SEND_VAR_EX                                              !8
         65        DO_FCALL                                      0  $54     
         66        ASSIGN                                                   !14, $54
   64    67    >   POST_DEC                                         ~56     !5
         68      > JMPNZ                                                    ~56, ->57
   63    69    >   POST_DEC                                         ~57     !4
         70      > JMPNZ                                                    ~57, ->55
   69    71    >   INIT_FCALL                                               'test'
         72        SEND_VAL                                                 'bag'
         73        DO_FCALL                                      0          
   71    74        INIT_FCALL                                               'var_dump'
         75        SEND_VAR                                                 !13
         76        DO_ICALL                                                 
   72    77        INIT_FCALL                                               'var_dump'
         78        SEND_VAR                                                 !14
         79        DO_ICALL                                                 
         80      > RETURN                                                   1

Function test:
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 = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/HJWvQ
function name:  test
number of ops:  23
compiled vars:  !0 = $label, !1 = $t, !2 = $t2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV_INIT                                        !0      ''
    5     1        BIND_GLOBAL                                              !1, 't'
    6     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
    7     6      > JMPZ                                                     !0, ->21
          7    >   INIT_FCALL                                               'str_pad'
          8        CONCAT                                           ~5      !0, '%3A+'
          9        SEND_VAL                                                 ~5
         10        SEND_VAL                                                 32
         11        SEND_VAL                                                 '.'
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $6      
         14        CONCAT                                           ~7      $6, '+'
         15        SUB                                              ~8      !2, !1
         16        MUL                                              ~9      ~8, 1000
         17        CONCAT                                           ~10     ~7, ~9
         18        CONCAT                                           ~11     ~10, 'ms'
         19        CONCAT                                           ~12     ~11, '%0A'
         20        ECHO                                                     ~12
    8    21    >   ASSIGN                                                   !1, !2
    9    22      > RETURN                                                   null

End of function test

Function %00%7Bclosure%7D%2Fin%2FHJWvQ%3A30%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HJWvQ
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $meh1, !1 = $meh2, !2 = $meh3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   31     3        INIT_METHOD_CALL                                         !0, 'hem'
          4        DO_FCALL                                      0  $3      
          5        INIT_METHOD_CALL                                         !1, 'hem'
          6        DO_FCALL                                      0  $4      
          7        ADD                                              ~5      $3, $4
          8        INIT_METHOD_CALL                                         !2, 'hem'
          9        DO_FCALL                                      0  $6      
         10        ADD                                              ~7      ~5, $6
         11      > RETURN                                                   ~7
   32    12*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHJWvQ%3A30%240

Function %00%7Bclosure%7D%2Fin%2FHJWvQ%3A34%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HJWvQ
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $bag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        FETCH_OBJ_R                                      ~1      !0, 'meh1'
          2        INIT_METHOD_CALL                                         ~1, 'hem'
          3        DO_FCALL                                      0  $2      
          4        FETCH_OBJ_R                                      ~3      !0, 'meh2'
          5        INIT_METHOD_CALL                                         ~3, 'hem'
          6        DO_FCALL                                      0  $4      
          7        ADD                                              ~5      $2, $4
          8        FETCH_OBJ_R                                      ~6      !0, 'meh3'
          9        INIT_METHOD_CALL                                         ~6, 'hem'
         10        DO_FCALL                                      0  $7      
         11        ADD                                              ~8      ~5, $7
         12      > RETURN                                                   ~8
   36    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHJWvQ%3A34%241

Class Meh:
Function hem:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HJWvQ
function name:  hem
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E > > RETURN                                                   1
          1*     > RETURN                                                   null

End of function hem

End of class Meh.

Class MehBag:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HJWvQ
function name:  __construct
number of ops:  8
compiled vars:  !0 = $meh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        ASSIGN_OBJ                                               'meh1'
          2        OP_DATA                                                  !0
   25     3        ASSIGN_OBJ                                               'meh2'
          4        OP_DATA                                                  !0
   26     5        ASSIGN_OBJ                                               'meh3'
          6        OP_DATA                                                  !0
   27     7      > RETURN                                                   null

End of function __construct

End of class MehBag.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.66 ms | 1411 KiB | 22 Q