3v4l.org

run code in 300+ PHP versions simultaneously
<?php function modern_strtok(string $string, string $delim): \Generator { $pos = 0; while (true) { $pos += \strspn($string, $delim, $pos); $len = \strcspn($string, $delim, $pos); if (!$len) return; $delim = (yield \substr($string, $pos, $len)) ?? $delim; $pos += $len; } } $string = ' -- This -- is an example -string '; $delim = ' -'; foreach (modern_strtok($string, $delim) as $tok) { var_dump($tok); } echo "************\n"; // changing $delim mid-course for ($g = modern_strtok($string, $delim); $g->valid(); $g->send($delim)) { var_dump($g->current()); $delim = ' '; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
Branch analysis from position: 20
Branch analysis from position: 12
filename:       /in/926tC
function name:  (null)
number of ops:  33
compiled vars:  !0 = $string, !1 = $delim, !2 = $tok, !3 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, '+--++This+--+is+an+example+-string+'
   17     1        ASSIGN                                                   !1, '+-'
   19     2        INIT_FCALL                                               'modern_strtok'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $6      
          6      > FE_RESET_R                                       $7      $6, ->12
          7    > > FE_FETCH_R                                               $7, !2, ->12
   20     8    >   INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                                 
   19    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $7
   23    13        ECHO                                                     '%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%0A'
   26    14        INIT_FCALL                                               'modern_strtok'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        DO_FCALL                                      0  $9      
         18        ASSIGN                                                   !3, $9
         19      > JMP                                                      ->29
   27    20    >   INIT_FCALL                                               'var_dump'
         21        INIT_METHOD_CALL                                         !3, 'current'
         22        DO_FCALL                                      0  $11     
         23        SEND_VAR                                                 $11
         24        DO_ICALL                                                 
   28    25        ASSIGN                                                   !1, '+'
   26    26        INIT_METHOD_CALL                                         !3, 'send'
         27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0          
         29    >   INIT_METHOD_CALL                                         !3, 'valid'
         30        DO_FCALL                                      0  $15     
         31      > JMPNZ                                                    $15, ->20
   29    32    > > RETURN                                                   1

Function modern_strtok:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 5
Branch analysis from position: 31
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 5
Branch analysis from position: 31
Branch analysis from position: 5
filename:       /in/926tC
function name:  modern_strtok
number of ops:  32
compiled vars:  !0 = $string, !1 = $delim, !2 = $pos, !3 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
    4     3        ASSIGN                                                   !2, 0
    5     4      > JMP                                                      ->30
    6     5    >   INIT_FCALL                                               'strspn'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $5      
         10        ASSIGN_OP                                     1          !2, $5
    7    11        INIT_FCALL                                               'strcspn'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !3, $7
    8    17        BOOL_NOT                                         ~9      !3
         18      > JMPZ                                                     ~9, ->20
    9    19    > > GENERATOR_RETURN                                         
   10    20    >   INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !2
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $10     
         25        YIELD                                            $11     $10
         26        COALESCE                                         ~12     $11
         27        QM_ASSIGN                                        ~12     !1
         28        ASSIGN                                                   !1, ~12
   11    29        ASSIGN_OP                                     1          !2, !3
    5    30    > > JMPNZ                                                    <true>, ->5
   13    31    > > GENERATOR_RETURN                                         

End of function modern_strtok

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
124.03 ms | 1465 KiB | 19 Q