v0.2.0 2021-01-10 10:20 UTC

This package is auto-updated.

Last update: 2021-04-10 10:49:24 UTC


This project provides a so-called InstantiationPrinter. I'm not the only one who has attempted to build such a thing:

Example: $instance = new self(); In PHP-Parser nodes this will be:

    0: Stmt_Expression(
        expr: Expr_Assign(
            var: Expr_Variable(
                name: instance
            expr: Expr_New(
                class: Name(
                    parts: array(
                        0: self
                args: array(

When printed by the InstantiationPrinter this becomes:

new PhpParser\Node\Stmt\Expression(
    new PhpParser\Node\Expr\Assign(
        new PhpParser\Node\Expr\Variable('instance'),
        new PhpParser\Node\Expr\New_(
            new PhpParser\Node\Name('self')


After installing this library in your project, you'll have command-line tool that generates the nodes based on the provided PHP script:

bin/print-node-instantiation-code temp.php

(if you don't have a bin/ directory in your project, try vendor/bin)

You can also instantiate your own InstantiationPrinter service. Take a look at the code in the print-node-instantiation-code script to find out how to accomplish this.