編者註:此行為是由於 PHP 7 的向下相容性考量,可能會在 PHP 9 中修復。
2024-02-14
PHP 8.3
interface AnyType {}
interface Type2 {}
function test (AnyType|null $param) {}
ReflectionParameter 將返回 ReflectionNamedType,而不是 ReflectionUnionType(基本上忽略 null)。
然而,function test (AnyType|Type2|null $param) {}
將返回具有 3 種類型而不是 2 種的 ReflectionUnionType(這次不忽略 null)。
對我來說,這只是 PHP 中的錯誤和邏輯錯誤。