3v4l.org

run code in 300+ PHP versions simultaneously
<?php // test-closures.php $division = function($a, $b) { return $a/$b; }; function doMath(Closure $function, $a, $b) { $result = $function($a, $b); return function() use ($result) {echo $result;}; } $callback = doMath($division, 9, 3); $callback().PHP_EOL; // 3 $callback = doMath(function($a, $b) { return $a * $b; }, 9, 2); // 18 $callback().PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Ss14
function name:  (null)
number of ops:  24
compiled vars:  !0 = $division, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0Ss14%3A4%240'
          1        ASSIGN                                                   !0, ~2
   15     2        INIT_FCALL                                               'domath'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 9
          5        SEND_VAL                                                 3
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !1, $4
   16     8        INIT_DYNAMIC_CALL                                        !1
          9        DO_FCALL                                      0  $6      
         10        CONCAT                                           ~7      $6, '%0A'
         11        FREE                                                     ~7
   18    12        INIT_FCALL                                               'domath'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0Ss14%3A18%242'
         14        SEND_VAL                                                 ~8
         15        SEND_VAL                                                 9
         16        SEND_VAL                                                 2
         17        DO_FCALL                                      0  $9      
         18        ASSIGN                                                   !1, $9
   19    19        INIT_DYNAMIC_CALL                                        !1
         20        DO_FCALL                                      0  $11     
         21        CONCAT                                           ~12     $11, '%0A'
         22        FREE                                                     ~12
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F0Ss14%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Ss14
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        DIV                                              ~2      !0, !1
          3      > RETURN                                                   ~2
    7     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0Ss14%3A4%240

Function domath:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Ss14
function name:  doMath
number of ops:  12
compiled vars:  !0 = $function, !1 = $a, !2 = $b, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   11     3        INIT_DYNAMIC_CALL                                        !0
          4        SEND_VAR_EX                                              !1
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !3, $4
   12     8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0Ss14%3A12%241'
          9        BIND_LEXICAL                                             ~6, !3
         10      > RETURN                                                   ~6
   13    11*     > RETURN                                                   null

End of function domath

Function %00%7Bclosure%7D%2Fin%2F0Ss14%3A12%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Ss14
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   BIND_STATIC                                              !0
          1        ECHO                                                     !0
          2      > RETURN                                                   null

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

Function %00%7Bclosure%7D%2Fin%2F0Ss14%3A18%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Ss14
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        MUL                                              ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0Ss14%3A18%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.76 ms | 1403 KiB | 15 Q