Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
while.test | 2017-07-31 | 59 Bytes | |
traitUse.test | 2017-07-31 | 337 Bytes | |
tryCatch.test | 2017-07-31 | 188 Bytes | |
switch.test | 2017-07-31 | 656 Bytes | |
throw.test | 2017-07-31 | 44 Bytes | |
namespaces.test | 2017-07-31 | 376 Bytes | |
nullable_types.test | 2017-07-31 | 163 Bytes | |
if.test | 2017-07-31 | 124 Bytes | |
multiCatch.test | 2017-07-31 | 186 Bytes | |
groupUse.test | 2017-07-31 | 300 Bytes | |
haltCompiler.file-test | 2017-07-31 | 219 Bytes | |
global_static_variables.test | 2017-07-31 | 194 Bytes | |
goto.test | 2017-07-31 | 65 Bytes | |
foreach.test | 2017-07-31 | 285 Bytes | |
function_signatures.test | 2017-07-31 | 899 Bytes | |
do_while.test | 2017-07-31 | 69 Bytes | |
for.test | 2017-07-31 | 252 Bytes | |
const.test | 2017-07-31 | 172 Bytes | |
declare.test | 2017-07-31 | 188 Bytes | |
class.test | 2017-07-31 | 759 Bytes | |
class_const.test | 2017-07-31 | 311 Bytes | |
alias.test | 2017-07-31 | 313 Bytes | |
break_continue.test | 2017-07-31 | 109 Bytes | |
Totals: 23 Items | 6.3 kB | 0 |
PHP Parser
This is a PHP 5.2 to PHP 7.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation.
Documentation for version 3.x (stable; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.1).
Documentation for version 2.x (stable; for running on PHP >= 5.4; for parsing PHP 5.2 to PHP 7.0).
Documentation for version 1.x (unsupported; for running on PHP >= 5.3; for parsing PHP 5.2 to PHP 5.6).
In a Nutshell
The parser turns PHP source code into an abstract syntax tree. For example, if you pass the following code into the parser:
<?php
echo 'Hi', 'World';
hello\world('foo', 'bar' . 'baz');
You'll get a syntax tree looking roughly like this:
array(
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hi
)
1: Scalar_String(
value: World
)
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: hello
1: world
)
)
args: array(
0: Arg(
value: Scalar_String(
value: foo
)
byRef: false
)
1: Arg(
value: Expr_Concat(
left: Scalar_String(
value: bar
)
right: Scalar_String(
value: baz
)
)
byRef: false
)
)
)
)
You can then work with this syntax tree, for example to statically analyze the code (e.g. to find programming errors or security issues).
Additionally, you can convert a syntax tree back to PHP code. This allows you to do code preprocessing (like automatedly porting code to older PHP versions).
Installation
The preferred installation method is composer:
php composer.phar require nikic/php-parser
Documentation
Component documentation: