PHPackages                             bhittani/php-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. bhittani/php-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

bhittani/php-parser
===================

Syntax parser with back porting down to previous versions.

0.1.9(9y ago)0182MITPHPPHP &gt;=5.4,&lt;8.0-DEV

Since Dec 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kamalkhan/php-parser)[ Packagist](https://packagist.org/packages/bhittani/php-parser)[ Docs](http://github.com/kamalkhan/php-parser)[ RSS](/packages/bhittani-php-parser/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (11)Used By (0)

PHP Parser [![Build Status](https://camo.githubusercontent.com/9937c859688d320a572acf90d36002c72f854366a81962bde237f39451f1e2fa/68747470733a2f2f7472617669732d63692e6f72672f6b616d616c6b68616e2f7068702d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kamalkhan/php-parser)
======================================================================================================================================================================================================================================================================================================

[](#php-parser-)

Syntax parser with back porting down to previous versions.

This library contains custom traversal visitors for use with [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser).

Table of contents
-----------------

[](#table-of-contents)

- [Table of contents](#table-of-contents)
- [Install](#install)
- [Usage](#usage)
    - [Group import to individual imports](#group-import-to-individual-imports)
    - [Splat calls to call\_user\_func\_array](#splat-calls-to-calluserfuncarray)
    - [Class constants to strings](#class-constants-to-strings)
    - [Variadic to func\_get\_args](#variadic-to-funcgetargs)
    - [Remove imports](#remove-imports)
    - [Append suffix](#append-suffix)
- [Test](#test)
- [Credits](#credits)
- [License](#license)

Install
-------

[](#install)

This library may be consumed by using [composer](https://getcomposer.org).

In your terminal, run:

```
$ composer require bhittani/php-parser
```

Usage
-----

[](#usage)

To utilize this library make sure you understand how [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser/blob/2.x/doc/2_Usage_of_basic_components.markdown#node-traversation) parses code.

This library contains a set of node visitors to manipulate php code.

#### Group import to individual imports

[](#group-import-to-individual-imports)

Back ports php 7+ syntax code.

```
use Bhittani\PhpParser\GroupToSingleImportsVisitor;

$traverser->addVisitor(new GroupToSingleImportsVisitor);
```

> which will convert

```
use Grouped\Imports\{Acme, Foo\Bar}
```

> into

```
use Grouped\Imports\Acme;
use Grouped\Imports\Foo\Bar;
```

#### Splat calls to call\_user\_func\_array

[](#splat-calls-to-call_user_func_array)

Back ports php 5.6+ syntax code.

```
use Bhittani\PhpParser\SplatToCallUserFuncArrayVisitor;

$traverser->addVisitor(new SplatToCallUserFuncArrayVisitor);
```

> which will convert

```
$val = my_func($a, 'b', ...$params);
```

> into

```
$val = call_user_func_array('my_func', array_merge(array(
    $a, 'b'
), $params));
```

#### Class constants to strings

[](#class-constants-to-strings)

Back ports php 5.5+ syntax code.

```
use Bhittani\PhpParser\ClassConstToStrVisitor;

$traverser->addVisitor(new ClassConstToStrVisitor);
```

> which will convert

```
use Acme\Foo\Bar;

$barClass = Bar::class;
```

> into

```
use Acme\Foo\Bar;

$barClass = 'Acme\Foo\Bar';
```

#### Variadic to func\_get\_args

[](#variadic-to-func_get_args)

Back ports php 5.6+ syntax code.

```
use Bhittani\PhpParser\VariadicToFuncGetArgsVisitor;

$traverser->addVisitor(new VariadicToFuncGetArgsVisitor);
```

> which will convert

```
function my_func($a, $b, ...$params)
{
    // my_func code
}
```

> into

```
function my_func()
{
    $params = func_get_args();
    $a = array_shift($params);
    $b = array_shift($params);

    // my_func code
}
```

#### Remove imports

[](#remove-imports)

Removes all import statements.

```
use Bhittani\PhpParser\RemoveImportsVisitor;

$traverser->addVisitor(new RemoveImportsVisitor);
```

> which will remove all `use` statements.

#### Append suffix

[](#append-suffix)

Appends a suffix to all imports, classes, traits, and interfaces.

```
use Bhittani\PhpParser\AppendSuffixVisitor;

$traverser->addVisitor(new AppendSuffixVisitor('_1'));
```

> which will convert

```
