Skip to content

Instantly share code, notes, and snippets.

@nikic
Created September 11, 2011 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nikic/1209494 to your computer and use it in GitHub Desktop.
Save nikic/1209494 to your computer and use it in GitHub Desktop.
Evil code
<?php
class PHPTokenizer_Tokenizer_PHP53To536 extends PHPTokenizer_Tokenizer_Base
{
public function tokenize($code) {
@$resetErrorMsg;
$tokens = @token_get_all($code);
$error = error_get_last();
try {
$this->checkError($error['message']);
$count = count($tokens);
for ($i = 0; $i < $count; ++$i) {
if (T_HALT_COMPILER === $tokens[$i][0]) {
$needTokens = 3;
for (; $i < $count; ++$i) {
if (!isset(self::$dropTokens[$tokens[$i][0]]) && !--$needTokens) {
$tokens = array_slice($tokens, 0, $i);
$rest = '';
for (; $i < $count; ++$i) {
if (isset($tokens[$i][1])) {
$rest .= $tokens[$i][1];
} else {
$rest .= $tokens[$i];
}
}
if ('' !== $rest) {
$tokens[] = array(T_INLINE_HTML, $rest, -1); // TODO: -1
}
}
}
}
}
} catch (PHPTokenizer_Error $e) {
// TODO: everything
}
return $tokens;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment