3v4l.org

run code in 300+ PHP versions simultaneously
<?php function run_test($name, $callback, $iterations) { $result = $callback(); echo "ran '$name' with result ", var_export($result, true), "\n"; } class Foo { } class Bar { function setup() {} } $method1 = function($test) { return function () use ($test) { if (method_exists($test, 'setup')) { $test->setup(); } }; }; $method2 = function($test) { $func = method_exists($test, 'setup') ? function() use ($test) { $test->setup(); } : function () {}; return function () use ($func) { $func(); }; }; $method3 = function($test) { $test = method_exists($test, 'setup') ? [$test, 'setup'] : function () {}; return function () use ($test) { $test(); }; }; const ITERATIONS = 1; run_test('foo1', $method1(new Foo()), ITERATIONS); run_test('bar1', $method1(new Bar()), ITERATIONS); run_test('foo2', $method2(new Foo()), ITERATIONS); run_test('bar2', $method2(new Bar()), ITERATIONS); run_test('foo3', $method3(new Foo()), ITERATIONS); run_test('bar3', $method3(new Bar()), ITERATIONS);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  (null)
number of ops:  74
compiled vars:  !0 = $method1, !1 = $method2, !2 = $method3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A18%240'
          1        ASSIGN                                                   !0, ~3
   27     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A27%242'
          3        ASSIGN                                                   !1, ~5
   37     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A37%246'
          5        ASSIGN                                                   !2, ~7
   47     6        DECLARE_CONST                                            'ITERATIONS', 1
   49     7        INIT_FCALL                                               'run_test'
          8        SEND_VAL                                                 'foo1'
          9        INIT_DYNAMIC_CALL                                        !0
         10        NEW                                              $9      'Foo'
         11        DO_FCALL                                      0          
         12        SEND_VAR_NO_REF_EX                                       $9
         13        DO_FCALL                                      0  $11     
         14        SEND_VAR                                                 $11
         15        FETCH_CONSTANT                                   ~12     'ITERATIONS'
         16        SEND_VAL                                                 ~12
         17        DO_FCALL                                      0          
   50    18        INIT_FCALL                                               'run_test'
         19        SEND_VAL                                                 'bar1'
         20        INIT_DYNAMIC_CALL                                        !0
         21        NEW                                              $14     'Bar'
         22        DO_FCALL                                      0          
         23        SEND_VAR_NO_REF_EX                                       $14
         24        DO_FCALL                                      0  $16     
         25        SEND_VAR                                                 $16
         26        FETCH_CONSTANT                                   ~17     'ITERATIONS'
         27        SEND_VAL                                                 ~17
         28        DO_FCALL                                      0          
   52    29        INIT_FCALL                                               'run_test'
         30        SEND_VAL                                                 'foo2'
         31        INIT_DYNAMIC_CALL                                        !1
         32        NEW                                              $19     'Foo'
         33        DO_FCALL                                      0          
         34        SEND_VAR_NO_REF_EX                                       $19
         35        DO_FCALL                                      0  $21     
         36        SEND_VAR                                                 $21
         37        FETCH_CONSTANT                                   ~22     'ITERATIONS'
         38        SEND_VAL                                                 ~22
         39        DO_FCALL                                      0          
   53    40        INIT_FCALL                                               'run_test'
         41        SEND_VAL                                                 'bar2'
         42        INIT_DYNAMIC_CALL                                        !1
         43        NEW                                              $24     'Bar'
         44        DO_FCALL                                      0          
         45        SEND_VAR_NO_REF_EX                                       $24
         46        DO_FCALL                                      0  $26     
         47        SEND_VAR                                                 $26
         48        FETCH_CONSTANT                                   ~27     'ITERATIONS'
         49        SEND_VAL                                                 ~27
         50        DO_FCALL                                      0          
   55    51        INIT_FCALL                                               'run_test'
         52        SEND_VAL                                                 'foo3'
         53        INIT_DYNAMIC_CALL                                        !2
         54        NEW                                              $29     'Foo'
         55        DO_FCALL                                      0          
         56        SEND_VAR_NO_REF_EX                                       $29
         57        DO_FCALL                                      0  $31     
         58        SEND_VAR                                                 $31
         59        FETCH_CONSTANT                                   ~32     'ITERATIONS'
         60        SEND_VAL                                                 ~32
         61        DO_FCALL                                      0          
   56    62        INIT_FCALL                                               'run_test'
         63        SEND_VAL                                                 'bar3'
         64        INIT_DYNAMIC_CALL                                        !2
         65        NEW                                              $34     'Bar'
         66        DO_FCALL                                      0          
         67        SEND_VAR_NO_REF_EX                                       $34
         68        DO_FCALL                                      0  $36     
         69        SEND_VAR                                                 $36
         70        FETCH_CONSTANT                                   ~37     'ITERATIONS'
         71        SEND_VAL                                                 ~37
         72        DO_FCALL                                      0          
         73      > RETURN                                                   1

Function run_test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  run_test
number of ops:  17
compiled vars:  !0 = $name, !1 = $callback, !2 = $iterations, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        INIT_DYNAMIC_CALL                                        !1
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !3, $4
    6     6        ROPE_INIT                                     3  ~7      'ran+%27'
          7        ROPE_ADD                                      1  ~7      ~7, !0
          8        ROPE_END                                      2  ~6      ~7, '%27+with+result+'
          9        ECHO                                                     ~6
         10        INIT_FCALL                                               'var_export'
         11        SEND_VAR                                                 !3
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $9      
         14        ECHO                                                     $9
         15        ECHO                                                     '%0A'
    7    16      > RETURN                                                   null

End of function run_test

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A19%241'
          2        BIND_LEXICAL                                             ~1, !0
   23     3      > RETURN                                                   ~1
   24     4*     > RETURN                                                   null

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

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A19%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/HKHqu
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   BIND_STATIC                                              !0
   20     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->8
   21     6    >   INIT_METHOD_CALL                                         !0, 'setup'
          7        DO_FCALL                                      0          
   23     8    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A19%241

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A27%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $test, !1 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $2      
          5      > JMPZ                                                     $2, ->10
   29     6    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A29%243'
          7        BIND_LEXICAL                                             ~3, !0
          8        QM_ASSIGN                                        ~4      ~3
          9      > JMP                                                      ->12
   30    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A30%244'
         11        QM_ASSIGN                                        ~4      ~5
   28    12    >   ASSIGN                                                   !1, ~4
   31    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A31%245'
         14        BIND_LEXICAL                                             ~7, !1
   33    15      > RETURN                                                   ~7
   34    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A27%242

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A29%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   BIND_STATIC                                              !0
          1        INIT_METHOD_CALL                                         !0, 'setup'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A29%243

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A30%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A30%244

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A31%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   BIND_STATIC                                              !0
   32     1        INIT_DYNAMIC_CALL                                        !0
          2        DO_FCALL                                      0          
   33     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A31%245

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A37%246:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   38     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->10
   39     6    >   INIT_ARRAY                                       ~2      !0
          7        ADD_ARRAY_ELEMENT                                ~2      'setup'
          8        QM_ASSIGN                                        ~3      ~2
          9      > JMP                                                      ->12
   40    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A40%247'
         11        QM_ASSIGN                                        ~3      ~4
   38    12    >   ASSIGN                                                   !0, ~3
   41    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHKHqu%3A41%248'
         14        BIND_LEXICAL                                             ~6, !0
   43    15      > RETURN                                                   ~6
   44    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A37%246

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A40%247:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A40%247

Function %00%7Bclosure%7D%2Fin%2FHKHqu%3A41%248:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   BIND_STATIC                                              !0
   42     1        INIT_DYNAMIC_CALL                                        !0
          2        DO_FCALL                                      0          
   43     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHKHqu%3A41%248

Class Foo: [no user functions]
Class Bar:
Function setup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HKHqu
function name:  setup
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E > > RETURN                                                   null

End of function setup

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.74 ms | 1415 KiB | 23 Q