Skip to content

Commit 20ef3ef

Browse files
author
n.gnato
committed
Add note about union types logic
1 parent d7061f2 commit 20ef3ef

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/FreeElephants/JsonApi/DTO/AbstractDocument.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ final public function __construct(array $payload)
1919
/** @var \ReflectionUnionType $reflectionType */
2020
$dataClassName = $reflectionType->getTypes()[0]->getName();
2121
}
22+
23+
/**
24+
* In cases like:
25+
* `public array|Example\ResourceObjectExt|Example\ResourceObject $data;`
26+
* ReflectionUnionType::getTypes() return types in next orders:
27+
* - Example\ResourceObjectExt
28+
* - Example\ResourceObject
29+
* - array
30+
*
31+
* This exception is [can] not covered with test. But this behavior not documented at https://www.php.net/manual/en/reflectionuniontype.gettypes.php
32+
*/
2233
if ($dataClassName !== 'array') {
2334
$data = new $dataClassName($payload['data']);
2435
} else {

0 commit comments

Comments
 (0)