3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace Test; $function = function () { return $a + $b . "Hello {$c} World!"; }; // Reflect the closure and fetch relevant properties $reflection = new \ReflectionFunction($function); $fileName = $reflection->getFileName(); $startLine = $reflection->getStartLine(); $endLine = $reflection->getEndLine(); // Slice out the lines $lines = array_slice(file($fileName), $startLine - 1, ($endLine - $startLine) + 1); $code = sprintf('<?php %s ; ?>', implode($lines)); // Tokenize and filter T_WHITESPACE $tokens = array_filter(token_get_all($code), function ($token) { if (is_array($token)) { if ($token[0] == T_WHITESPACE) { return false; } } return true; }); // Dump for shits and giggles foreach ($tokens as $token) { echo PHP_EOL; if (is_array($token)) { echo str_pad(token_name($token[0]), 30, '.') . trim($token[1]); continue; } echo str_pad('SYMBOL', 30, '.') . $token; }
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
T_OPEN_TAG....................<?php T_VARIABLE....................$function SYMBOL........................= T_FUNCTION....................function SYMBOL........................( SYMBOL........................) SYMBOL........................{ T_RETURN......................return T_VARIABLE....................$a SYMBOL........................+ T_VARIABLE....................$b SYMBOL......................... SYMBOL........................" T_ENCAPSED_AND_WHITESPACE.....Hello T_CURLY_OPEN..................{ T_VARIABLE....................$c SYMBOL........................} T_ENCAPSED_AND_WHITESPACE.....World! SYMBOL........................" SYMBOL........................; SYMBOL........................} SYMBOL........................; SYMBOL........................; T_CLOSE_TAG...................?>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/LU4S3 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/LU4S3 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/LU4S3 on line 3
Process exited with code 255.