3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_phrases($sentence) { $inQuotes = false; $quoteChars = ['"', "'"]; $separators = [' ']; $phrase = null; $res = []; for ($i = 0; $i < strlen($sentence); $i++) { $t = $sentence[$i]; $isOpenQuote = !$inQuotes && in_array($t, $quoteChars); $isCloseQuote = $t == $inQuotes; $isLast = $i+1 == strlen($sentence); $isSeparator = !$inQuotes && in_array($t, $separators); if (!$inQuotes && $isOpenQuote) { // Opening quote $inQuotes = $t; continue; } elseif ($inQuotes && $isCloseQuote) { // Closing quote $inQuotes = false; } if (!$isOpenQuote && !$isCloseQuote && !$isSeparator) { $phrase .= $t; } if ($isSeparator || $isLast) { //yield $phrase; // or add to an array in pre-5.5 $res[] = $phrase; $phrase = null; } } return $res; } function assertEquals($expected, $actual) { if ($actual !== $expected) { echo sprintf("Assertion failed: %s does not equal %s\n", print_r($actual, true), print_r($expected, true) ); } else { echo "Assertion passed\n"; } } assertEquals(['Hello', 'world'], get_phrases('Hello world')); assertEquals(['I', 'am', 'a', 'foo bar'], 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/adaDE
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   INIT_FCALL                                               'assertequals'
          1        SEND_VAL                                                 <array>
          2        INIT_FCALL                                               'get_phrases'
          3        SEND_VAL                                                 'Hello+world'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_FCALL                                      0          
   52     7        INIT_FCALL                                               'assertequals'
          8        SEND_VAL                                                 <array>
          9        INIT_FCALL                                               'get_phrases'
         10        SEND_VAL                                                 'I+am+a+%27foo+bar%27'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

Function get_phrases:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 8
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 8
Branch analysis from position: 62
Branch analysis from position: 8
Branch analysis from position: 39
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 43
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
2 jumps found. (Code = 46) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 52
Branch analysis from position: 51
2 jumps found. (Code = 47) Position 1 = 53, Position 2 = 54
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 58
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 8
Branch analysis from position: 62
Branch analysis from position: 8
Branch analysis from position: 58
Branch analysis from position: 54
Branch analysis from position: 52
Branch analysis from position: 50
Branch analysis from position: 47
Branch analysis from position: 43
Branch analysis from position: 41
Branch analysis from position: 35
Branch analysis from position: 31
Branch analysis from position: 17
filename:       /in/adaDE
function name:  get_phrases
number of ops:  64
compiled vars:  !0 = $sentence, !1 = $inQuotes, !2 = $quoteChars, !3 = $separators, !4 = $phrase, !5 = $res, !6 = $i, !7 = $t, !8 = $isOpenQuote, !9 = $isCloseQuote, !10 = $isLast, !11 = $isSeparator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <false>
    4     2        ASSIGN                                                   !2, <array>
    5     3        ASSIGN                                                   !3, <array>
    6     4        ASSIGN                                                   !4, null
    7     5        ASSIGN                                                   !5, <array>
    9     6        ASSIGN                                                   !6, 0
          7      > JMP                                                      ->59
   10     8    >   FETCH_DIM_R                                      ~18     !0, !6
          9        ASSIGN                                                   !7, ~18
   12    10        BOOL_NOT                                         ~20     !1
         11      > JMPZ_EX                                          ~20     ~20, ->17
         12    >   INIT_FCALL                                               'in_array'
         13        SEND_VAR                                                 !7
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $21     
         16        BOOL                                             ~20     $21
         17    >   ASSIGN                                                   !8, ~20
   13    18        IS_EQUAL                                         ~23     !7, !1
         19        ASSIGN                                                   !9, ~23
   14    20        ADD                                              ~25     !6, 1
         21        STRLEN                                           ~26     !0
         22        IS_EQUAL                                         ~27     ~25, ~26
         23        ASSIGN                                                   !10, ~27
   15    24        BOOL_NOT                                         ~29     !1
         25      > JMPZ_EX                                          ~29     ~29, ->31
         26    >   INIT_FCALL                                               'in_array'
         27        SEND_VAR                                                 !7
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $30     
         30        BOOL                                             ~29     $30
         31    >   ASSIGN                                                   !11, ~29
   17    32        BOOL_NOT                                         ~32     !1
         33      > JMPZ_EX                                          ~32     ~32, ->35
         34    >   BOOL                                             ~32     !8
         35    > > JMPZ                                                     ~32, ->39
   19    36    >   ASSIGN                                                   !1, !7
   20    37      > JMP                                                      ->58
         38*       JMP                                                      ->43
   21    39    > > JMPZ_EX                                          ~34     !1, ->41
         40    >   BOOL                                             ~34     !9
         41    > > JMPZ                                                     ~34, ->43
   23    42    >   ASSIGN                                                   !1, <false>
   26    43    >   BOOL_NOT                                         ~36     !8
         44      > JMPZ_EX                                          ~36     ~36, ->47
         45    >   BOOL_NOT                                         ~37     !9
         46        BOOL                                             ~36     ~37
         47    > > JMPZ_EX                                          ~36     ~36, ->50
         48    >   BOOL_NOT                                         ~38     !11
         49        BOOL                                             ~36     ~38
         50    > > JMPZ                                                     ~36, ->52
   27    51    >   ASSIGN_OP                                     8          !4, !7
   30    52    > > JMPNZ_EX                                         ~40     !11, ->54
         53    >   BOOL                                             ~40     !10
         54    > > JMPZ                                                     ~40, ->58
   32    55    >   ASSIGN_DIM                                               !5
         56        OP_DATA                                                  !4
   33    57        ASSIGN                                                   !4, null
    9    58    >   PRE_INC                                                  !6
         59    >   STRLEN                                           ~44     !0
         60        IS_SMALLER                                               !6, ~44
         61      > JMPNZ                                                    ~45, ->8
   37    62    > > RETURN                                                   !5
   38    63*     > RETURN                                                   null

End of function get_phrases

Function assertequals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/adaDE
function name:  assertEquals
number of ops:  21
compiled vars:  !0 = $expected, !1 = $actual
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        IS_NOT_IDENTICAL                                         !1, !0
          3      > JMPZ                                                     ~2, ->19
   42     4    >   INIT_FCALL                                               'sprintf'
          5        SEND_VAL                                                 'Assertion+failed%3A+%25s+does+not+equal+%25s%0A'
   43     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
   44    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $4      
         15        SEND_VAR                                                 $4
         16        DO_ICALL                                         $5      
         17        ECHO                                                     $5
         18      > JMP                                                      ->20
   47    19    >   ECHO                                                     'Assertion+passed%0A'
   49    20    > > RETURN                                                   null

End of function assertequals

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
206.32 ms | 1407 KiB | 23 Q