diff --git a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php index 15cdcc4252a..6d8d8e617ae 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php @@ -25,12 +25,20 @@ public function __construct( */ public function __toString(): string { - $this->types = array_unique($this->types, SORT_REGULAR); + $types = []; + + // get the actual strings first before array_unique + // to avoid similar object but different printing to be treated as unique + foreach ($this->types as $type) { + $types[] = (string) $type; + } + + $types = array_unique($types); if (! $this->isWrappedInBrackets) { - return implode('|', $this->types); + return implode('|', $types); } - return '(' . implode('|', $this->types) . ')'; + return '(' . implode('|', $types) . ')'; } public function isWrappedInBrackets(): bool