Blame view

vendor/nikic/php-parser/README.md 2.89 KB
c4650843   Etienne Pallier   Ajout du dossier ...
1
2
3
4
5
PHP Parser
==========

[![Build Status](https://travis-ci.org/nikic/PHP-Parser.svg?branch=master)](https://travis-ci.org/nikic/PHP-Parser) [![Coverage Status](https://coveralls.io/repos/github/nikic/PHP-Parser/badge.svg?branch=master)](https://coveralls.io/github/nikic/PHP-Parser?branch=master)

d06254b2   Etienne Pallier   bugfix plugin mig...
6
This is a PHP 5.2 to PHP 7.1 parser written in PHP. Its purpose is to simplify static code analysis and
c4650843   Etienne Pallier   Ajout du dossier ...
7
8
manipulation.

d06254b2   Etienne Pallier   bugfix plugin mig...
9
[**Documentation for version 3.x**][doc_master] (stable; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.1).
c4650843   Etienne Pallier   Ajout du dossier ...
10

d06254b2   Etienne Pallier   bugfix plugin mig...
11
[Documentation for version 2.x][doc_2_x] (stable; for running on PHP >= 5.4; for parsing PHP 5.2 to PHP 7.0).
c4650843   Etienne Pallier   Ajout du dossier ...
12

d06254b2   Etienne Pallier   bugfix plugin mig...
13
[Documentation for version 1.x][doc_1_x] (unsupported; for running on PHP >= 5.3; for parsing PHP 5.2 to PHP 5.6).
c4650843   Etienne Pallier   Ajout du dossier ...
14

d06254b2   Etienne Pallier   bugfix plugin mig...
15
16
In a Nutshell
-------------
c4650843   Etienne Pallier   Ajout du dossier ...
17

d06254b2   Etienne Pallier   bugfix plugin mig...
18
19
The parser turns PHP source code into an abstract syntax tree. For example, if you pass the following code into the
parser:
c4650843   Etienne Pallier   Ajout du dossier ...
20
21
22

```php
<?php
d06254b2   Etienne Pallier   bugfix plugin mig...
23
24
echo 'Hi', 'World';
hello\world('foo', 'bar' . 'baz');
c4650843   Etienne Pallier   Ajout du dossier ...
25
26
```

d06254b2   Etienne Pallier   bugfix plugin mig...
27
You'll get a syntax tree looking roughly like this:
c4650843   Etienne Pallier   Ajout du dossier ...
28

d06254b2   Etienne Pallier   bugfix plugin mig...
29
```php
c4650843   Etienne Pallier   Ajout du dossier ...
30
array(
d06254b2   Etienne Pallier   bugfix plugin mig...
31
32
33
34
    0: Stmt_Echo(
        exprs: array(
            0: Scalar_String(
                value: Hi
c4650843   Etienne Pallier   Ajout du dossier ...
35
            )
d06254b2   Etienne Pallier   bugfix plugin mig...
36
37
            1: Scalar_String(
                value: World
c4650843   Etienne Pallier   Ajout du dossier ...
38
39
40
            )
        )
    )
d06254b2   Etienne Pallier   bugfix plugin mig...
41
42
43
44
45
46
    1: Expr_FuncCall(
        name: Name(
            parts: array(
                0: hello
                1: world
            )
c4650843   Etienne Pallier   Ajout du dossier ...
47
        )
d06254b2   Etienne Pallier   bugfix plugin mig...
48
49
50
51
52
        args: array(
            0: Arg(
                value: Scalar_String(
                    value: foo
                )
c4650843   Etienne Pallier   Ajout du dossier ...
53
                byRef: false
d06254b2   Etienne Pallier   bugfix plugin mig...
54
55
56
57
58
59
60
61
62
            )
            1: Arg(
                value: Expr_Concat(
                    left: Scalar_String(
                        value: bar
                    )
                    right: Scalar_String(
                        value: baz
                    )
c4650843   Etienne Pallier   Ajout du dossier ...
63
                )
d06254b2   Etienne Pallier   bugfix plugin mig...
64
                byRef: false
c4650843   Etienne Pallier   Ajout du dossier ...
65
66
            )
        )
c4650843   Etienne Pallier   Ajout du dossier ...
67
68
69
70
    )
)
```

d06254b2   Etienne Pallier   bugfix plugin mig...
71
72
You can then work with this syntax tree, for example to statically analyze the code (e.g. to find
programming errors or security issues).
c4650843   Etienne Pallier   Ajout du dossier ...
73

d06254b2   Etienne Pallier   bugfix plugin mig...
74
75
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).
c4650843   Etienne Pallier   Ajout du dossier ...
76

d06254b2   Etienne Pallier   bugfix plugin mig...
77
78
Installation
------------
c4650843   Etienne Pallier   Ajout du dossier ...
79

d06254b2   Etienne Pallier   bugfix plugin mig...
80
The preferred installation method is [composer](https://getcomposer.org):
c4650843   Etienne Pallier   Ajout du dossier ...
81

d06254b2   Etienne Pallier   bugfix plugin mig...
82
    php composer.phar require nikic/php-parser
c4650843   Etienne Pallier   Ajout du dossier ...
83
84
85
86
87
88

Documentation
-------------

 1. [Introduction](doc/0_Introduction.markdown)
 2. [Usage of basic components](doc/2_Usage_of_basic_components.markdown)
d06254b2   Etienne Pallier   bugfix plugin mig...
89
90
 3. [Other node tree representations](doc/3_Other_node_tree_representations.markdown)
 4. [Code generation](doc/4_Code_generation.markdown)
c4650843   Etienne Pallier   Ajout du dossier ...
91
92
93

Component documentation:

d06254b2   Etienne Pallier   bugfix plugin mig...
94
95
96
97
98
 1. [Error handling](doc/component/Error_handling.markdown)
 2. [Lexer](doc/component/Lexer.markdown)

 [doc_1_x]: https://github.com/nikic/PHP-Parser/tree/1.x/doc
 [doc_2_x]: https://github.com/nikic/PHP-Parser/tree/2.x/doc
c4650843   Etienne Pallier   Ajout du dossier ...
99
 [doc_master]: https://github.com/nikic/PHP-Parser/tree/master/doc