note 80335 added to function.token-get-all
| From: | rogier at dsone dot nl | Date: | Thu, 10 Jan 2008 16:37:37 +0000 |
| Subject: | note 80335 added to function.token-get-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135004@lists.php.net to get a copy of this message | ||
On several PHP versions (pre 5.1), if token_get_all is used, the result will NOT always return the
correct result.
This bug will only show (as far as I know) when PHP is loaded as a module. In the CLI the bug seems
non-existent.
Related here are bugs 29761 and 34782.
To work around this, here's a fixing function:
<?php
//fixes related bugs: 29761, 34782 => token_get_all returns <?php NOT as T_OPEN_TAG
function token_fix( &$tokens ) {
if (!is_array($tokens) || (count($tokens)<2)) {
return;
}
//return of no fixing needed
if (is_array($tokens[0]) && (($tokens[0][0]==T_OPEN_TAG) ||
($tokens[0][0]==T_OPEN_TAG_WITH_ECHO)) ) {
return;
}
//continue
$p1 = (is_array($tokens[0])?$tokens[0][1]:$tokens[0]);
$p2 = (is_array($tokens[1])?$tokens[1][1]:$tokens[1]);
$p3 = '';
if (($p1.$p2 == '<?') || ($p1.$p2 == '<%')) {
$type = ($p2=='?')?T_OPEN_TAG:T_OPEN_TAG_WITH_ECHO;
$del = 2;
//update token type for 3rd part?
if (count($tokens)>2) {
$p3 = is_array($tokens[2])?$tokens[2][1]:$tokens[2];
$del = (($p3=='php') || ($p3=='='))?3:2;
$type = ($p3=='=')?T_OPEN_TAG_WITH_ECHO:$type;
}
//rebuild erroneous token
$temp = array($type, $p1.$p2.$p3);
if (version_compare(phpversion(), '5.2.2', '<' )===false) {
$temp[] = $token[0][2];
}
//rebuild
$tokens[1] = '';
if ($del==3) $tokens[2]='';
$tokens[0] = $temp;
}
return;
}
?>
----
Server IP: 83.137.20.135
Probable Submitter: 62.45.6.85
----
Manual Page -- http://www.php.net/manual/en/function.token-get-all.php
Edit -- https://master.php.net/note/edit/80335
Del: integrated -- https://master.php.net/note/delete/80335/integrated
Del: useless -- https://master.php.net/note/delete/80335/useless
Del: bad code -- https://master.php.net/note/delete/80335/bad+code
Del: spam -- https://master.php.net/note/delete/80335/spam
Del: non-english -- https://master.php.net/note/delete/80335/non-english
Del: in docs -- https://master.php.net/note/delete/80335/in+docs
Del: other reasons-- https://master.php.net/note/delete/80335
Reject -- https://master.php.net/note/reject/80335
Search -- https://master.php.net/manage/user-notes.php