3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Token { function __construct($type = null, $content, $line = null){ $this->type = $type; $this->content = $content; $this->line = $line; } } $tokens = token_get_all('<?php // lol bar baz bar /* ( ) stuff */ bar '); foreach($tokens as $offset => $token){ $tokens[$offset] = is_array($token) ? new Token($token[0], $token[1], $token[2]) : new Token(null, $token, null); } print_r($tokens);
based on m9jXK
Output for 7.0.0 - 7.2.0
Array ( [0] => Token Object ( [type] => 379 [content] => <?php [line] => 1 ) [1] => Token Object ( [type] => 382 [content] => [line] => 1 ) [2] => Token Object ( [type] => 377 [content] => // lol bar baz [line] => 2 ) [3] => Token Object ( [type] => 319 [content] => bar [line] => 3 ) [4] => Token Object ( [type] => 382 [content] => [line] => 3 ) [5] => Token Object ( [type] => 377 [content] => /* ( ) stuff */ [line] => 3 ) [6] => Token Object ( [type] => 382 [content] => [line] => 10 ) [7] => Token Object ( [type] => 319 [content] => bar [line] => 11 ) [8] => Token Object ( [type] => 382 [content] => [line] => 11 ) )
Output for 5.6.8 - 5.6.28
Array ( [0] => Token Object ( [type] => 376 [content] => <?php [line] => 1 ) [1] => Token Object ( [type] => 379 [content] => [line] => 1 ) [2] => Token Object ( [type] => 374 [content] => // lol bar baz [line] => 2 ) [3] => Token Object ( [type] => 310 [content] => bar [line] => 3 ) [4] => Token Object ( [type] => 379 [content] => [line] => 3 ) [5] => Token Object ( [type] => 374 [content] => /* ( ) stuff */ [line] => 3 ) [6] => Token Object ( [type] => 379 [content] => [line] => 10 ) [7] => Token Object ( [type] => 310 [content] => bar [line] => 11 ) [8] => Token Object ( [type] => 379 [content] => [line] => 11 ) )
Output for 5.5.24 - 5.5.35
Array ( [0] => Token Object ( [type] => 374 [content] => <?php [line] => 1 ) [1] => Token Object ( [type] => 377 [content] => [line] => 1 ) [2] => Token Object ( [type] => 372 [content] => // lol bar baz [line] => 2 ) [3] => Token Object ( [type] => 308 [content] => bar [line] => 3 ) [4] => Token Object ( [type] => 377 [content] => [line] => 3 ) [5] => Token Object ( [type] => 372 [content] => /* ( ) stuff */ [line] => 3 ) [6] => Token Object ( [type] => 377 [content] => [line] => 10 ) [7] => Token Object ( [type] => 308 [content] => bar [line] => 11 ) [8] => Token Object ( [type] => 377 [content] => [line] => 11 ) )
Output for 5.4.9 - 5.4.45
Array ( [0] => Token Object ( [type] => 372 [content] => <?php [line] => 1 ) [1] => Token Object ( [type] => 375 [content] => [line] => 1 ) [2] => Token Object ( [type] => 370 [content] => // lol bar baz [line] => 2 ) [3] => Token Object ( [type] => 307 [content] => bar [line] => 3 ) [4] => Token Object ( [type] => 375 [content] => [line] => 3 ) [5] => Token Object ( [type] => 370 [content] => /* ( ) stuff */ [line] => 3 ) [6] => Token Object ( [type] => 375 [content] => [line] => 10 ) [7] => Token Object ( [type] => 307 [content] => bar [line] => 11 ) [8] => Token Object ( [type] => 375 [content] => [line] => 11 ) )
Output for 5.3.19 - 5.3.29
Array ( [0] => Token Object ( [type] => 368 [content] => <?php [line] => 1 ) [1] => Token Object ( [type] => 371 [content] => [line] => 1 ) [2] => Token Object ( [type] => 366 [content] => // lol bar baz [line] => 2 ) [3] => Token Object ( [type] => 307 [content] => bar [line] => 3 ) [4] => Token Object ( [type] => 371 [content] => [line] => 3 ) [5] => Token Object ( [type] => 366 [content] => /* ( ) stuff */ [line] => 3 ) [6] => Token Object ( [type] => 371 [content] => [line] => 10 ) [7] => Token Object ( [type] => 307 [content] => bar [line] => 11 ) [8] => Token Object ( [type] => 371 [content] => [line] => 11 ) )