3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_phrases($sentence) { $inQuotes = false; $quoteChars = ['"', "'"]; $separators = [' ', "\n"]; $phrase = null; foreach ((string) $sentence as $i => $t) { if (!$inQuotes && in_array($t, $quoteChars)) { // Opening quote $inQuotes = $t; } elseif ($inQuotes && $t == $inQuotes) { // Closing quote $inQuotes = false; } elseif (!$inQuotes && in_array($t, $separators)) { yield $phrase; // or add to an array in pre-5.5 $phrase = null; } else { $phrase .= $t; } } } var_dump((array) get_phrases('Hello world')); var_dump((array) get_phrases("I am a 'foo bar'"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GGdSB
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'get_phrases'
          2        SEND_VAL                                                 'Hello+world'
          3        DO_FCALL                                      0  $0      
          4        CAST                                          7  ~1      $0
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                                 
   25     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'get_phrases'
          9        SEND_VAL                                                 'I+am+a+%27foo+bar%27'
         10        DO_FCALL                                      0  $3      
         11        CAST                                          7  ~4      $3
         12        SEND_VAL                                                 ~4
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function get_phrases:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 39
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 39
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 33
Branch analysis from position: 23
Branch analysis from position: 17
Branch analysis from position: 39
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 39
filename:       /in/GGdSB
function name:  get_phrases
number of ops:  41
compiled vars:  !0 = $sentence, !1 = $inQuotes, !2 = $quoteChars, !3 = $separators, !4 = $phrase, !5 = $t, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    3     2        ASSIGN                                                   !1, <false>
    4     3        ASSIGN                                                   !2, <array>
    5     4        ASSIGN                                                   !3, <array>
    6     5        ASSIGN                                                   !4, null
    8     6        CAST                                          6  ~11     !0
          7      > FE_RESET_R                                       $12     ~11, ->39
          8    > > FE_FETCH_R                                       ~13     $12, !5, ->39
          9    >   ASSIGN                                                   !6, ~13
    9    10        BOOL_NOT                                         ~15     !1
         11      > JMPZ_EX                                          ~15     ~15, ->17
         12    >   INIT_FCALL                                               'in_array'
         13        SEND_VAR                                                 !5
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $16     
         16        BOOL                                             ~15     $16
         17    > > JMPZ                                                     ~15, ->20
   11    18    >   ASSIGN                                                   !1, !5
         19      > JMP                                                      ->38
   12    20    > > JMPZ_EX                                          ~18     !1, ->23
         21    >   IS_EQUAL                                         ~19     !5, !1
         22        BOOL                                             ~18     ~19
         23    > > JMPZ                                                     ~18, ->26
   14    24    >   ASSIGN                                                   !1, <false>
         25      > JMP                                                      ->38
   15    26    >   BOOL_NOT                                         ~21     !1
         27      > JMPZ_EX                                          ~21     ~21, ->33
         28    >   INIT_FCALL                                               'in_array'
         29        SEND_VAR                                                 !5
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $22     
         32        BOOL                                             ~21     $22
         33    > > JMPZ                                                     ~21, ->37
   16    34    >   YIELD                                                    !4
   17    35        ASSIGN                                                   !4, null
         36      > JMP                                                      ->38
   19    37    >   ASSIGN_OP                                     8          !4, !5
    8    38    > > JMP                                                      ->8
         39    >   FE_FREE                                                  $12
   22    40      > GENERATOR_RETURN                                         

End of function get_phrases

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.87 ms | 1406 KiB | 20 Q