Skip to content

Support PHP 8 union and intersection types - #5

Open
sgiehl wants to merge 1 commit into
dev-4.x-devphp8-twig-updatefrom
fix-union-and-intersection-types
Open

Support PHP 8 union and intersection types#5
sgiehl wants to merge 1 commit into
dev-4.x-devphp8-twig-updatefrom
fix-union-and-intersection-types

Conversation

@sgiehl

@sgiehl sgiehl commented Aug 24, 2026

Copy link
Copy Markdown
Member

UnionType and IntersectionType are the only type nodes that cannot be cast to string, so NodeVisitor threw Object of class PhpParser\Node\UnionType could not be converted to string when parsing a method that uses one.

Adds an elseif branch at both sites (parameter types ~L174, return types ~L224) and a shared getCompositeTypeAsString() helper.

Hit by Matomo 6: Piwik\Plugin\ConsoleCommand::handleSignal(int $signal): int|false aborts the whole API-reference generation for developer.matomo.org. Matomo 5 has no union types in the parsed scope, which is why this only surfaces now. Note the crash happens during parsing, before the class filter runs, so a non-@api class is enough to break the run.

Verified against the real generation: with this patch generator/generate.php --branch=6.x-dev completes with exit 0, and the output is byte-identical to a run using an inline version of the same fix.

Native property types need no equivalent change — addProperty() reads only the @var docblock.

UnionType and IntersectionType cannot be cast to string, so parsing a method with
such a parameter or return type threw 'Object of class PhpParser\Node\UnionType
could not be converted to string'.

Hit by Matomo 6, eg Piwik\Plugin\ConsoleCommand::handleSignal(): int|false.
sgiehl added a commit to matomo-org/developer-documentation that referenced this pull request Aug 24, 2026
Sami cannot cast UnionType/IntersectionType to string, so generating the 6.x API
reference aborted on eg ConsoleCommand::handleSignal(): int|false.

Points tsteur/sami at matomo-org/Sami#5 and raises the generator PHP floor to
7.2.5; the declared >=5.3.0 was long untrue.
sgiehl added a commit to matomo-org/developer-documentation that referenced this pull request Aug 25, 2026
Sami cannot cast UnionType/IntersectionType to string, so generating the 6.x API
reference aborted on the union-typed signatures matomo-php-tracker 4.0 introduced.

Points tsteur/sami at matomo-org/Sami#5 and raises the generator PHP floor to
8.1.0, matching what the locked dependencies actually require.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant