Lines Matching refs:to

4 This document explains how to use the parser, the pretty printer and the node traverser.
12 require 'path/to/vendor/autoload.php';
15 Additionally, you may want to set the `xdebug.max_nesting_level` ini option to a higher value:
22 preferable to disable Xdebug completely, as it can easily make this library more than five times
28 In order to parse code, you first have to create a parser instance:
44 Which version you should target depends on your use case. In many cases you will want to use the
47 to accept the widest range of code (unless there are breaking changes in PHP).
52 Subsequently, you can pass PHP code (including the opening `<?php` tag) to the `parse()` method in
53 order to create a syntax tree. If a syntax error is encountered, a `PhpParser\Error` exception will
79 A parser instance can be reused to parse multiple files.
154 You can also use the `php-parse` script to obtain such a node dump by calling it either with a file
162 This can be very helpful if you want to quickly check how certain syntax is represented in the AST.
174 reserved keyword. Many node class names in this library have a trailing `_` to avoid clashing with
177 As PHP is a large language there are approximately 140 different nodes. In order to make working
198 `$node->subNodeName`. The `Stmt\Echo_` node has only one subnode `exprs`. So in order to access it
199 in the above example you would write `$stmts[0]->exprs`. If you wanted to access the name of the fu…
206 It is possible to associate custom metadata with a node using the `setAttribute()` method. This data
220 The pretty printer component compiles the AST back to PHP code according to a specified scheme.
242 = 'Hello '; // change to 'Hello '
258 again converted to code using `PhpParser\PrettyPrinter\Standard->prettyPrint()`.
260 The `prettyPrint()` method pretty prints a statements array. It is also possible to pretty print on…
263 The `prettyPrintFile()` method can be used to print an entire file. This will include the opening `…
274 … above pretty printing example used the fact that the source code was known and thus it was easy to
276 Usually you want to change / analyze code in a generic way, where you don't know how the node tree …
277 going to look like.
327 The above node visitor would change all string literals in the program to `'foo'`.
343 The `afterTraverse()` method is similar to the `beforeTraverse()` method, with the only difference …
353 which instructs the traverser to skip all children of the current node. To furthermore prevent subs…
374 helps you work with namespaced code by trying to resolve most names to fully qualified ones.
381 In order to know that `B\C` really is `A\C` you would need to track aliases and namespaces yourself.
386 know which function they are referring to. In most cases this is a non-issue as the global functions
389 Additionally, the `NameResolver` adds a `namespacedName` subnode to class, function and constant
395 Example: Converting namespaced code to pseudo namespaces
398 A small example to understand the concept: We want to convert namespaced code to pseudo namespaces,
399 so it works on 5.2, i.e. names like `A\\B` should be converted to `A_B`. Note that such conversions
439 // write the converted file to the target directory
450 Now lets start with the main code, the `NamespaceConverter`. One thing it needs to do
451 is convert `A\\B` style names to `A_B` style ones.
467 possible, so we don't need to do that. We only need to create a string with the name parts separated
468 …tead of backslashes. This is what `str_replace('\\', '_', $node->toString())` does. (If you want to
472 Another thing we need to do is change the class/function/const declarations. Currently they contain
473 only the shortname (i.e. the last part of the name), but they need to contain the complete name inc…
498 There is not much more to it than converting the namespaced name to string with `_` as separator.
500 The last thing we need to do is remove the `namespace` and `use` statements: