3v4l.org

run code in 500+ PHP versions simultaneously
<?php // I have this string to start: $input = "eskimo> __adrian: it's for matching nicks in irc"; // I want to turn it into this string: $expected = "%eskimo%> %__adrian%: it's for matching nicks in irc"; $nicks = ["eskimo", "__adrian"]; $result = mark($input, ...$nicks); function mark(string $message, string ...$nicks) { $marks = array_map(fn($n) => "%{$n}%", $nicks); return strtr($message, array_combine($nicks, $marks)); } echo $result; assert($result === $expected);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hMb0Y
function name:  (null)
number of ops:  17
compiled vars:  !0 = $input, !1 = $expected, !2 = $nicks, !3 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                       !0, 'eskimo%3E+__adrian%3A+it%27s+for+matching+nicks+in+irc'
    9     1        ASSIGN                                                       !1, '%25eskimo%25%3E+%25__adrian%25%3A+it%27s+for+matching+nicks+in+irc'
   11     2        ASSIGN                                                       !2, <array>
   12     3        INIT_FCALL_BY_NAME                                           'mark'
          4        SEND_VAR_EX                                                  !0
          5        SEND_UNPACK                                                  !2
          6        CHECK_UNDEF_ARGS                                             
          7        DO_FCALL                                          1  $7      
          8        ASSIGN                                                       !3, $7
   18     9        ECHO                                                         !3
   19    10        ASSERT_CHECK                                                 
         11        INIT_FCALL                                                   'assert'
         12        IS_IDENTICAL                                         ~9      !3, !1
         13        SEND_VAL                                                     ~9
         14        SEND_VAL                                                     'assert%28%24result+%3D%3D%3D+%24expected%29'
         15        DO_ICALL                                                     
         16      > RETURN                                                       1

Function mark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hMb0Y
function name:  mark
number of ops:  15
compiled vars:  !0 = $message, !1 = $nicks, !2 = $marks
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV_VARIADIC                                        !1      
   14     2        INIT_FCALL                                                   'array_map'
          3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          4        SEND_VAL                                                     ~3
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !2, $4
   15     8        INIT_FCALL                                                   'array_combine'
          9        SEND_VAR                                                     !1
         10        SEND_VAR                                                     !2
         11        DO_ICALL                                             $6      
         12        FRAMELESS_ICALL_2                strtr               ~7      !0, $6
         13      > RETURN                                                       ~7
   16    14*     > 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/hMb0Y
function name:  {closure:mark():14}
number of ops:  6
compiled vars:  !0 = $n
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        ROPE_INIT                                         3  ~2      '%25'
          2        ROPE_ADD                                          1  ~2      ~2, !0
          3        ROPE_END                                          2  ~1      ~2, '%25'
          4      > RETURN                                                       ~1
          5*     > RETURN                                                       null

End of Dynamic Function 0

End of function mark

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
218.93 ms | 2002 KiB | 16 Q