本来想装到ubuntu上的,但是ubuntu的php是源码安装的,缺了个openssl库,重新整起来有点费劲,有空再弄吧,直接整了个Windows的
项目地址 https://github.com/nikic/PHP-Parser
下载 composer https://getcomposer.org/Composer-Setup.exe
安装好之后执行命令
composer require nikic/php-parser
<?php
require '.\vendor\autoload.php';
use PhpParser\Error;
use PhpParser\NodeDumper;
use PhpParser\ParserFactory;
$code = <<<'CODE'
<?php
function test($foo)
{
var_dump($foo);
}
CODE;
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
try {
$ast = $parser->parse($code);
} catch (Error $error) {
echo "Parse error: {$error->getMessage()}\n";
return;
}
$dumper = new NodeDumper;
echo $dumper->dump($ast) . "\n";
如果用不了的试试下面的安装方法,上面好像有点坑,最近忙毕业先不管了
php -r "readfile('https://getcomposer.org/installer');" | php
php composer.phar install