3v4l.org

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

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

End of function run_test

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

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A11%240

Function %00%7Bclosure%7D%2Fin%2FHjsG9%3A12%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/HjsG9
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   BIND_STATIC                                              !0
   13     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->8
   14     6    >   INIT_METHOD_CALL                                         !0, 'setup'
          7        DO_FCALL                                      0          
   16     8    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A12%241

Function %00%7Bclosure%7D%2Fin%2FHjsG9%3A19%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/HjsG9
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $test, !1 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $2      
          5      > JMPZ                                                     $2, ->10
   21     6    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHjsG9%3A21%243'
          7        BIND_LEXICAL                                             ~3, !0
          8        QM_ASSIGN                                        ~4      ~3
          9      > JMP                                                      ->12
   22    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHjsG9%3A22%244'
         11        QM_ASSIGN                                        ~4      ~5
   20    12    >   ASSIGN                                                   !1, ~4
   23    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHjsG9%3A23%245'
         14        BIND_LEXICAL                                             ~7, !1
   25    15      > RETURN                                                   ~7
   26    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A19%242

Function %00%7Bclosure%7D%2Fin%2FHjsG9%3A21%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HjsG9
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     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%2FHjsG9%3A21%243

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

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A22%244

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

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A23%245

Function %00%7Bclosure%7D%2Fin%2FHjsG9%3A28%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/HjsG9
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->10
   30     6    >   INIT_ARRAY                                       ~2      !0
          7        ADD_ARRAY_ELEMENT                                ~2      'setup'
          8        QM_ASSIGN                                        ~3      ~2
          9      > JMP                                                      ->12
   31    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHjsG9%3A31%247'
         11        QM_ASSIGN                                        ~3      ~4
   29    12    >   ASSIGN                                                   !0, ~3
   32    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHjsG9%3A32%248'
         14        BIND_LEXICAL                                             ~6, !0
   34    15      > RETURN                                                   ~6
   35    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A28%246

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

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A31%247

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

End of function %00%7Bclosure%7D%2Fin%2FHjsG9%3A32%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/HjsG9
function name:  setup
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E > > RETURN                                                   null

End of function setup

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.23 ms | 1415 KiB | 23 Q