3v4l.org

run code in 300+ PHP versions simultaneously
<?php function updateYear(string $text, int $newYear): string { $year = null; $result = preg_replace_callback( '/(\-)(\d\d\d\d)/', function (array $matches) use ($newYear, &$year): string { $year = (int) $matches[2]; return $matches[1] . (string) $newYear; }, $text ); return "Replaced {$year} in '{$text} => '{$result}'"; } echo updateYear('(c) 1970-2022', 2023) . PHP_EOL; echo updateYear('(c) 1999-2022', 2023) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RovuX
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'updateyear'
          1        SEND_VAL                                                 '%28c%29+1970-2022'
          2        SEND_VAL                                                 2023
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      $0, '%0A'
          5        ECHO                                                     ~1
   20     6        INIT_FCALL                                               'updateyear'
          7        SEND_VAL                                                 '%28c%29+1999-2022'
          8        SEND_VAL                                                 2023
          9        DO_FCALL                                      0  $2      
         10        CONCAT                                           ~3      $2, '%0A'
         11        ECHO                                                     ~3
   21    12      > RETURN                                                   1

Function updateyear:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RovuX
function name:  updateYear
number of ops:  23
compiled vars:  !0 = $text, !1 = $newYear, !2 = $year, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, null
    7     3        INIT_FCALL                                               'preg_replace_callback'
    8     4        SEND_VAL                                                 '%2F%28%5C-%29%28%5Cd%5Cd%5Cd%5Cd%29%2F'
    9     5        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
          6        BIND_LEXICAL                                             ~5, !1
          7        BIND_LEXICAL                                             ~5, !2
   12     8        SEND_VAL                                                 ~5
   13     9        SEND_VAR                                                 !0
    7    10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !3, $6
   16    12        ROPE_INIT                                     7  ~9      'Replaced+'
         13        ROPE_ADD                                      1  ~9      ~9, !2
         14        ROPE_ADD                                      2  ~9      ~9, '+in+%27'
         15        ROPE_ADD                                      3  ~9      ~9, !0
         16        ROPE_ADD                                      4  ~9      ~9, '+%3D%3E+%27'
         17        ROPE_ADD                                      5  ~9      ~9, !3
         18        ROPE_END                                      6  ~8      ~9, '%27'
         19        VERIFY_RETURN_TYPE                                       ~8
         20      > RETURN                                                   ~8
   17    21*       VERIFY_RETURN_TYPE                                       
         22*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RovuX
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $matches, !1 = $newYear, !2 = $year
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   10     3        FETCH_DIM_R                                      ~3      !0, 2
          4        CAST                                          4  ~4      ~3
          5        ASSIGN                                                   !2, ~4
   11     6        FETCH_DIM_R                                      ~6      !0, 1
          7        CAST                                          6  ~7      !1
          8        CONCAT                                           ~8      ~6, ~7
          9        VERIFY_RETURN_TYPE                                       ~8
         10      > RETURN                                                   ~8
   12    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of Dynamic Function 0

End of function updateyear

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.98 ms | 1452 KiB | 16 Q