3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected $bar; public function init($callable) { $callable($this, $this->bar); } public function setBar($bar) { $this->bar = $bar; } } $a = new A(); $callable1 = function($obj, &$bar) { $bar = 'foo'; }; $callable2 = function($obj, &$bar) { $obj->setBar('foo'); }; foreach (array($callable1, $callable2) as $cb) { $start = microtime(true); for ($i = 0; $i < 100000; $i += 1) { $a->init($cb); } var_dump(microtime(true) - $start); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 31
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 31
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
Branch analysis from position: 17
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/SWSNp
function name:  (null)
number of ops:  33
compiled vars:  !0 = $a, !1 = $callable1, !2 = $callable2, !3 = $cb, !4 = $start, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $6      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $6
   18     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSWSNp%3A18%240'
          4        ASSIGN                                                   !1, ~9
   22     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSWSNp%3A22%241'
          6        ASSIGN                                                   !2, ~11
   26     7        INIT_ARRAY                                       ~13     !1
          8        ADD_ARRAY_ELEMENT                                ~13     !2
          9      > FE_RESET_R                                       $14     ~13, ->31
         10    > > FE_FETCH_R                                               $14, !3, ->31
   27    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $15     
         14        ASSIGN                                                   !4, $15
   28    15        ASSIGN                                                   !5, 0
         16      > JMP                                                      ->21
   29    17    >   INIT_METHOD_CALL                                         !0, 'init'
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0          
   28    20        ASSIGN_OP                                     1          !5, 1
         21    >   IS_SMALLER                                               !5, 100000
         22      > JMPNZ                                                    ~20, ->17
   31    23    >   INIT_FCALL                                               'var_dump'
         24        INIT_FCALL                                               'microtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $21     
         27        SUB                                              ~22     $21, !4
         28        SEND_VAL                                                 ~22
         29        DO_ICALL                                                 
   26    30      > JMP                                                      ->10
         31    >   FE_FREE                                                  $14
   32    32      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FSWSNp%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SWSNp
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $obj, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        ASSIGN                                                   !1, 'foo'
   20     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSWSNp%3A18%240

Function %00%7Bclosure%7D%2Fin%2FSWSNp%3A22%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SWSNp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $obj, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        INIT_METHOD_CALL                                         !0, 'setBar'
          3        SEND_VAL_EX                                              'foo'
          4        DO_FCALL                                      0          
   24     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSWSNp%3A22%241

Class A:
Function init:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SWSNp
function name:  init
number of ops:  9
compiled vars:  !0 = $callable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        INIT_DYNAMIC_CALL                                        !0
          2        FETCH_THIS                                       $1      
          3        SEND_VAR_EX                                              $1
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $2      'bar'
          6        SEND_FUNC_ARG                                            $2
          7        DO_FCALL                                      0          
    9     8      > RETURN                                                   null

End of function init

Function setbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SWSNp
function name:  setBar
number of ops:  4
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
   13     3      > RETURN                                                   null

End of function setbar

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.29 ms | 1400 KiB | 17 Q