@ 2015-12-10T10:30:10Z <?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);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 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 . Output for 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 Fatal error: Using $this when not in object context in /in/MStua on line 14
Process exited with code 255 . preferences:dark mode live preview
233.35 ms | 401 KiB | 323 Q