Skip to content

Support for php 8.0 ReflectionUnionType in lib/Dispatcher.phpΒ #35

@TysonAndre

Description

@TysonAndre

https://wiki.php.net/rfc/union_types_v2 was merged.

This introduces ReflectionUnionType extends ReflectionType. https://wiki.php.net/rfc/union_types_v2#reflection - ReflectionUnionType->getTypes() should be used if it exists. (similar to how phpdoc union types are used).

The existing code wouldn't work, because $class = (string)$paramType would contain |.

Also, I think that nullable types may get converted to ?stdClass in 8.0 in nullable types of union types

                            if ($paramType instanceof ReflectionNamedType) {
                                // We have object data to map and want the class name.
                                // This should not include the `?` if the type was nullable.
                                $class = $paramType->getName();
                            } else {
                                // Fallback for php 7.0, which is still supported (and doesn't have nullable).
                                $class = (string)$paramType;
                            }
                            $value = $this->mapper->map($value, new $class());

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions