3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parse_tokens($code) { $ns = ''; $tokens = token_get_all($code); /* Assume token 0 = '<?php' and token 1 = whitespace */ for ($i = 2, $c = count($tokens); $i < $c; ++$i) { if (!is_array($tokens[$i])) { continue; } switch ($tokens[$i][0]) { case T_CLASS: list($class, $i) = $this->parse_class($tokens, $i); if ($class) { $test = $this->instantiate_test($loader, $ns . $class); if ($test) { $this->runner->run_test_case($test); } } break; case T_NAMESPACE: //list($ns, $i) = $this->parse_namespace($tokens, $i, $ns); break; } } } function parse_class($tokens, $i) { /* $i = 'class' and $i+1 = whitespace */ $i += 2; while (!is_array($tokens[$i]) || T_STRING !== $tokens[$i][0]) { ++$i; } $class = $tokens[$i][1]; print "$class\n"; if (0 === stripos($class, 'test')) { return [$class, $i]; } return [false, $i]; } $file = <<<'FILE' class TestTextBefore {} <?php /* class TestComment {} */ class Test {} <<<STRING class TestString {} STRING; class test2 { public function test1() {} public function test2() {} public function test3() {} } class NotATest {} class // valid tokens between the 'class' keyword and the test name /* should be handled correctly */ Test3 {} ?> class TestTestAfter {} FILE; parse_tokens($file);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Using $this when not in object context in /in/MStua:14 Stack trace: #0 /in/MStua(76): parse_tokens('class TestTextB...') #1 {main} thrown in /in/MStua on line 14
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.53 ms | 401 KiB | 8 Q