Skip to content

Commit 8460826

Browse files
committed
Fix union return types
1 parent 71262d0 commit 8460826

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/php/lang.base.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ function typeof($arg) {
386386
if ($t instanceof \ReflectionUnionType) {
387387
$union= [];
388388
foreach ($t->getTypes() as $c) {
389-
$union[]= \lang\Type::forName(PHP_VERSION_ID >= 70100 ? $c->getName() : $c->__toString());
389+
$union[]= \lang\Type::forName($c->getName());
390390
}
391391
$signature[]= new \lang\TypeUnion($union);
392392
} else {
@@ -397,7 +397,15 @@ function typeof($arg) {
397397
}
398398
}
399399
if ($t= $r->getReturnType()) {
400-
$return= \lang\Type::forName(PHP_VERSION_ID >= 70100 ? $t->getName() : $t->__toString());
400+
if ($t instanceof \ReflectionUnionType) {
401+
$union= [];
402+
foreach ($t->getTypes() as $c) {
403+
$union[]= \lang\Type::forName($c->getName());
404+
}
405+
$return= new \lang\TypeUnion($union);
406+
} else {
407+
$return= \lang\Type::forName(PHP_VERSION_ID >= 70100 ? $t->getName() : $t->__toString());
408+
}
401409
} else {
402410
$return= \lang\Type::$VAR;
403411
}

0 commit comments

Comments
 (0)