} elseif ($token[0] == T_ECHO) {
$in_echo = true;
} elseif ($token[1] == ';' && $in_echo) {
- if ($tokens[$i+1][0] === T_WHITESPACE && $tokens[$i+2][0] === T_ECHO) {
+ $next_echo = next_token($tokens, $i, T_ECHO, array(T_WHITESPACE, T_COMMENT));
+ for (; $i < $next_echo - 1; $i++) {
next($tokens);
- $i++;
}
- if ($tokens[$i+1][0] === T_ECHO) {
+ if ($next_echo) {
// join two consecutive echos
next($tokens);
$token[1] = ','; // '.' would conflict with "a".1+2 and would use more memory //! remove ',' and "," but not $var","
return $output;
}
+function next_token($tokens, $i, $search, $allowed = array()) {
+ for ($i += 1; in_array($tokens[$i][0], $allowed); $i++) {
+ }
+ return ($tokens[$i][0] === $search ? $i : 0);
+}
+
function short_identifier($number, $chars) {
$return = '';
while ($number >= 0) {
//! bugs:
check('{if (true) {} echo 1;}', '{if(true);echo 1;}');
-//! inefficiencies:
-check("echo 1; //\necho 2;", 'echo 1,2;');
-
check('$ab = 1; echo $ab;', '$a=1;echo$a;');
check('$ab = 1; $cd = 2;', '$a=1;$b=2;');
check('define("AB", 1);', 'define("AB",1);');
check('echo $_GET["a"];', 'echo$_GET["a"];');
check('$ab = 1; echo "$ab";', '$a=1;echo"$a";');
check('echo 1; echo 3;', 'echo 1,3;');
+check('echo 1; /**/ echo 2;', 'echo 1,2;');
check('echo 1; ?>2<?php echo 3;', "echo 1,'2',3;");
check('/** preserve */ $a; /** ignore */ /* also ignore */ // ignore too', '/** preserve */$a;');
check('$a = 1; ?><?php ?><?php $a = 2;', '$a=1;$a=2;');