迁移到php 8.6前,可以用php-parser对旧源码建立函数调用清单,记录文件、行号和静态函数名称,再据此安排人工迁移。当前读取的php-parser文档把完整解析范围列到php 8.4,因此以下扫描限定在该语法范围内的遗留文件,不承诺能解析php 8.6新语法,也不执行被扫描源码。
安装并限制输入目录
使用composer require --dev nikic/php-parser:^5.9。将脚本保存为scan.php,在项目根目录运行,代码只扫描src目录的.php普通文件,并跳过符号链接。不要将来自用户的任意服务器路径直接传给扫描器。

PHP-Parser官方文档中的解析器版本选择
遍历AST并保留动态调用的边界
<?php require __DIR__.'/vendor/autoload.php';
use PhpParser\ParserFactory;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
__DIR__.'/src', FilesystemIterator::SKIP_DOTS));
$failed = false;
foreach ($files as $file) {
if (!$file->isFile() || $file->isLink() || $file->getExtension() !== 'php') { continue; }
$visitor = new class extends NodeVisitorAbstract {
public array $calls = [];
public function enterNode(Node $node) {
if ($node instanceof Node\Expr\FuncCall) {
$this->calls[] = ['line' => $node->getStartLine(),
'name' => $node->name instanceof Node\Name
? $node->name->toString() : null,
'dynamic' => !($node->name instanceof Node\Name)];
}
}
};
try {
$source = file_get_contents($file->getPathname());
if ($source === false) { throw new RuntimeException('Cannot read file'); }
$ast = $parser->parse($source) ?? [];
$traverser = new NodeTraverser();
$traverser->addVisitor($visitor);
$traverser->traverse($ast);
foreach ($visitor->calls as $call) {
echo json_encode(['file' => $file->getPathname()] + $call,
JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR), PHP_EOL;
}
} catch (Throwable $e) {
$failed = true;
fwrite(STDERR, $file->getPathname().': '.$e->getMessage().PHP_EOL);
}
}
exit($failed ? 1 : 0);

PHP-Parser官方文档中的节点遍历示例节选
按清单检查,不能把名称等同于内置函数
输出中的name是源码中写出的名称,不一定是最终解析到的全限定名称:命名空间函数、use function别名和同名用户函数都需要进一步核对。dynamic为true的调用不能从静态名称推断目标。该清单不包含方法调用,也不证明某个函数在运行时一定执行;它适合定位候选,不适合自动替换。解析失败的文件必须保留在失败清单里,升级解析器或另行检查后再处理。
使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










