<?php

namespace PhpToZephir\Converter\Printer\Expr;

use PhpParser\Node\Expr;
use PhpToZephir\Converter\SimplePrinter;

class NewPrinter extends SimplePrinter
{
    public static function getType()
    {
        return "pExpr_New";
    }

    public function convert(Expr\New_ $node)
    {
        if ($node->class instanceof \PhpParser\Node\Expr\Variable) {
            return 'new {' . $this->dispatcher->p($node->class) . '}(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
        }
        return 'new ' . $this->dispatcher->p($node->class) . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
    }
}

<?php

namespace PhpToZephir\Converter\Printer\Expr;

use PhpParser\Node\Expr;
use PhpToZephir\Converter\SimplePrinter;

class NewPrinter extends SimplePrinter
{
    public static function getType()
    {
        return "pExpr_New";
    }

    public function convert(Expr\New_ $node)
    {
        return 'new '.$this->dispatcher->p($node->class).'('.$this->dispatcher->pCommaSeparated($node->args).')';
    }
}

--- 
+++ 
@@ -14,6 +14,9 @@
 
     public function convert(Expr\New_ $node)
     {
-        return 'new '.$this->dispatcher->p($node->class).'('.$this->dispatcher->pCommaSeparated($node->args).')';
+        if ($node->class instanceof \PhpParser\Node\Expr\Variable) {
+            return 'new {' . $this->dispatcher->p($node->class) . '}(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
+        }
+        return 'new ' . $this->dispatcher->p($node->class) . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')';
     }
 }
Fix New object from variable name