Inserting array item with comment ----- 'foo', 'b' => 'bar', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); $node->setAttribute('comments', [new Comment\Doc(<<expr->expr; $array->items[] = $node; ----- 'foo', 'b' => 'bar', /** * A doc comment */ 'c' => 'baz', ]; ----- 'foo', 'b' => 'bar', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); $node->setAttribute('comments', [new Comment("/* Block comment */")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', 'b' => 'bar', /* Block comment */ 'c' => 'baz', ]; ----- 'foo', 'b' => 'bar', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); $node->setAttribute('comments', [new Comment("// Line comment")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', 'b' => 'bar', // Line comment 'c' => 'baz', ]; ----- 'foo', ]; ----- $node = new Expr\ArrayItem(new Scalar\String_('bar'), new Scalar\String_('b')); $node->setAttribute('comments', [new Comment("// Line comment")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', // Line comment 'b' => 'bar', ]; ----- setAttribute('comments', [new Comment("// Line comment")]); $array = $stmts[0]->expr->expr; $array->items[] = $node; ----- 'foo', ];