PEAR_Common::analyzeSourceCode and PHP5 detection
| From: | Laurent Laville | Date: | Tue, 28 Feb 2006 21:13:07 +0000 |
| Subject: | PEAR_Common::analyzeSourceCode and PHP5 detection | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-41550@lists.php.net to get a copy of this message | ||
While testing again PEAR_PackageFileManager2 1.6.0a7 (upcoming release) with PEAR 1.4.7 and my proposal for a web frontend for PFM, I discovered wrong PHP5 source code detection.
I took Text_Highlighter 0.6.9 as source code reference for many test cases.
With "Highlighter\Generator.php" file and lines 1100 to 1122
PEAR_Common::analyzeSourceCode told us that
"PHP5 token encountered in [...] packaging should be done in PHP 5"
This is due to phpdoc @public considered as PHP5 token public.
Scripts test:
file: codeparse.php
<?php
$code = <<<CODE
/**
* PHP4 Compatible Constructor
*
* @param array \$options
* @access public
*/
function Text_Highlighter_{$this->language}(\$options=array())
{
\$this->__construct(\$options);
}
CODE;
?>
file: studycase.php
<?php
require_once 'PEAR/Common.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
$c = new PEAR_Common();
$c->analyzeSourceCode('codeparse.php');
?>
ouput result:
Error: PHP5 token encountered in codeparse.phppackaging should be done in PHP 5
file: studycase2.php
<?php
$contents = file_get_contents('codeparse.php');
$tokens = token_get_all($contents);
echo '<pre>'; print_r($tokens); echo '</pre>';
for ($i = 0; $i < sizeof($tokens); $i++) {
if (is_array($tokens[$i])) {
list($token, $data) = $tokens[$i];
} else {
$token = $tokens[$i];
$data = '';
}
if ($token == T_STRING) {
if (in_array(strtolower($data),
array('public', 'private', 'protected', 'abstract',
'interface', 'implements', 'throw')
)) {
echo '<pre>'; print_r($i); print_r($data); echo '</pre>';
}
}
}
?>
output result:
25 public ==> corresponding to phpdoc @public
25 stand for T_STRING on my platform (PHP 4.4.2 win32)
Token stories is back !!!
Laurent Laville