Linux unitednationsplay.com 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
nginx/1.20.1
Server IP : 188.130.139.92 & Your IP : 3.133.142.101
Domains :
Cant Read [ /etc/named.conf ]
User : web
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
home /
www /
3 /
nikic /
php-parser /
doc /
component /
Delete
Unzip
Name
Size
Permission
Date
Action
AST_builders.markdown
5.24
KB
-rw-r--r--
2018-10-10 09:00
Constant_expression_evaluation.markdown
3.31
KB
-rw-r--r--
2018-10-10 09:00
Error_handling.markdown
2.69
KB
-rw-r--r--
2018-10-10 09:00
FAQ.markdown
2.06
KB
-rw-r--r--
2018-10-10 09:00
JSON_representation.markdown
3.4
KB
-rw-r--r--
2018-10-10 09:00
Lexer.markdown
7.55
KB
-rw-r--r--
2018-10-10 09:00
Name_resolution.markdown
4.04
KB
-rw-r--r--
2018-10-10 09:00
Performance.markdown
3.25
KB
-rw-r--r--
2018-10-10 09:00
Pretty_printing.markdown
4.1
KB
-rw-r--r--
2018-10-10 09:00
Walking_the_AST.markdown
11.3
KB
-rw-r--r--
2018-10-10 09:00
Save
Rename
JSON representation =================== Nodes (and comments) implement the `JsonSerializable` interface. As such, it is possible to JSON encode the AST directly using `json_encode()`: ```php <?php use PhpParser\ParserFactory; $code = <<<'CODE' <?php /** @param string $msg */ function printLine($msg) { echo $msg, "\n"; } CODE; $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); try { $stmts = $parser->parse($code); echo json_encode($stmts, JSON_PRETTY_PRINT), "\n"; } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); } ``` This will result in the following output (which includes attributes): ```json [ { "nodeType": "Stmt_Function", "byRef": false, "name": { "nodeType": "Identifier", "name": "printLine", "attributes": { "startLine": 4, "endLine": 4 } }, "params": [ { "nodeType": "Param", "type": null, "byRef": false, "variadic": false, "var": { "nodeType": "Expr_Variable", "name": "msg", "attributes": { "startLine": 4, "endLine": 4 } }, "default": null, "attributes": { "startLine": 4, "endLine": 4 } } ], "returnType": null, "stmts": [ { "nodeType": "Stmt_Echo", "exprs": [ { "nodeType": "Expr_Variable", "name": "msg", "attributes": { "startLine": 5, "endLine": 5 } }, { "nodeType": "Scalar_String", "value": "\n", "attributes": { "startLine": 5, "endLine": 5, "kind": 2 } } ], "attributes": { "startLine": 5, "endLine": 5 } } ], "attributes": { "startLine": 4, "comments": [ { "nodeType": "Comment_Doc", "text": "\/** @param string $msg *\/", "line": 3, "filePos": 9, "tokenPos": 2 } ], "endLine": 6 } } ] ``` The JSON representation may be converted back into an AST using the `JsonDecoder`: ```php <?php $nodeDecoder = new PhpParser\NodeDecoder(); $ast = $nodeDecoder->decode($json); ``` Note that not all ASTs can be represented using JSON. In particular: * JSON only supports UTF-8 strings. * JSON does not support non-finite floating-point numbers. This can occur if the original source code contains non-representable floating-pointing literals such as `1e1000`. If the node tree is not representable in JSON, the initial `json_encode()` call will fail. From the command line, a JSON dump can be obtained using `vendor/bin/php-parse -j file.php`.