3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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(get_phrases('Hello world')); var_dump(get_phrases("I am a 'foo bar'");
Output for 5.4.0 - 5.4.29
Parse error: syntax error, unexpected '$phrase' (T_VARIABLE) in /in/UKLT7 on line 16
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '[' in /in/UKLT7 on line 4
Process exited with code 255.