3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'foo'; $replacement = 'bar'; $str1 = preg_replace_callback('/^foo$/', function($match) { global $replacement; return $replacement; }, $str); $str2 = preg_replace_callback('/^foo$/', function($match, &$replacement) { return $replacement; }, $str); var_dump($str1); var_dump($str2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/buOI7
function name:  (null)
number of ops:  23
compiled vars:  !0 = $str, !1 = $replacement, !2 = $str1, !3 = $str2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'foo'
    4     1        ASSIGN                                                   !1, 'bar'
    6     2        INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAL                                                 '%2F%5Efoo%24%2F'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FbuOI7%3A6%240'
   10     5        SEND_VAL                                                 ~6
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $7      
    6     8        ASSIGN                                                   !2, $7
   12     9        INIT_FCALL                                               'preg_replace_callback'
         10        SEND_VAL                                                 '%2F%5Efoo%24%2F'
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FbuOI7%3A12%241'
   14    12        SEND_VAL                                                 ~9
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $10     
   12    15        ASSIGN                                                   !3, $10
   16    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                                 
   17    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FbuOI7%3A6%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/buOI7
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $match, !1 = $replacement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        BIND_GLOBAL                                              !1, 'replacement'
    9     2      > RETURN                                                   !1
   10     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FbuOI7%3A6%240

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.26 ms | 1388 KiB | 17 Q