diff --git a/src/PhpGenerator/Printer.php b/src/PhpGenerator/Printer.php index 40485a57..469bf95f 100644 --- a/src/PhpGenerator/Printer.php +++ b/src/PhpGenerator/Printer.php @@ -422,7 +422,7 @@ protected function printAttributes(array $attrs, bool $inline = false): string foreach ($attrs as $attr) { $args = $this->dumper->format('...?:', $attr->getArguments()); $args = Helpers::simplifyTaggedNames($args, $this->namespace); - $items[] = $this->printType($attr->getName(), nullable: false) . ($args ? "($args)" : ''); + $items[] = $this->printType($attr->getName(), nullable: false) . ($args !== '' ? "($args)" : ''); $inline = $inline && !str_contains($args, "\n"); } diff --git a/tests/PhpGenerator/Printer.attribute.phpt b/tests/PhpGenerator/Printer.attribute.phpt new file mode 100644 index 00000000..a9176add --- /dev/null +++ b/tests/PhpGenerator/Printer.attribute.phpt @@ -0,0 +1,23 @@ +addAttribute('MyAttribute', [0]); + +same( + <<<'XX' + #[MyAttribute(0)] + class Classy + { + } + + XX, + (string) $classy, +);