# Reflection changes due to allow null + false as standalone types RFC

- Thread: https://externals.io/message/117477
- Original archive: https://news-web.php.net/php.internals/117477
- Started by G. P. B. on 2022-04-05T11:58:14+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #117477 — G. P. B. — 2022-04-05T11:58:14+00:00

URL: https://externals.io/message/117477#117477

Hello internals,

During the review of the implementation of the RFC which introduces null
and false as standalone types there has been a point raised about the
changes made to reflection. [1]

The current implementation is what follows the RFC, namely to make
false|null return a ReflectionUnionType instead of a ReflectionNamedType.
Because of this, I made the rendering of this type union to be false|null
instead of ?false.

Moreover, the question is if this union type should not be consistent with
other types and produce a ReflectionNamedType, and have all of the nullable
types move to ReflectionUnionType at the same time.

I don't mind either way, but as this was voted part of the RFC I feel this
should be discussed by internals to see if changing the Reflection
semantics to not align with the RFC is okay.

As there are currently the following options:
- Keep as the RFC stated with some minor implementation complexity which
will be resolved when the Reflection changes are made to all other nullable
types.
- Ignore the Reflection changes of the RFC and align the union type with
the current behaviour
- Break BC and change all nullable types to return a ReflectionUnionType

(I just added the last option for the sake of completeness, but don't think
breaking BC is the way to go here).

Best regards,

George P. Banyard

[1] https://github.com/php/php-src/pull/7546#discussion_r837900447

---

## #117478 — Marco Pivetta — 2022-04-05T12:00:53+00:00

URL: https://externals.io/message/117477#117478 · In reply to: #117477

Probably best with consistency?

 > - Ignore the Reflection changes of the RFC and align the union type with
the current behaviour

This one, specifically.

I'd love to see all nullable types become
`ReflectionUnionType(ReflectionNamedType($t), ReflectionNamedType(null))`,
but that would be a BC break for later on :-)

Marco Pivetta

https://twitter.com/Ocramius

https://ocramius.github.io/




> Hello internals,
>
> During the review of the implementation of the RFC which introduces null
> and false as standalone types there has been a point raised about the
> changes made to reflection. [1]
>
> The current implementation is what follows the RFC, namely to make
> false|null return a ReflectionUnionType instead of a ReflectionNamedType.
> Because of this, I made the rendering of this type union to be false|null
> instead of ?false.
>
> Moreover, the question is if this union type should not be consistent with
> other types and produce a ReflectionNamedType, and have all of the nullable
> types move to ReflectionUnionType at the same time.
>
> I don't mind either way, but as this was voted part of the RFC I feel this
> should be discussed by internals to see if changing the Reflection
> semantics to not align with the RFC is okay.
>
> As there are currently the following options:
> - Keep as the RFC stated with some minor implementation complexity which
> will be resolved when the Reflection changes are made to all other nullable
> types.
> - Ignore the Reflection changes of the RFC and align the union type with
> the current behaviour
> - Break BC and change all nullable types to return a ReflectionUnionType
>
> (I just added the last option for the sake of completeness, but don't think
> breaking BC is the way to go here).
>
> Best regards,
>
> George P. Banyard
>
> [1] https://github.com/php/php-src/pull/7546#discussion_r837900447

---

## #117480 — Guilliam Xavier — 2022-04-06T11:36:12+00:00

URL: https://externals.io/message/117477#117480 · In reply to: #117478

Hi George,

> https://github.com/php/php-src/pull/7546#discussion_r837900447

Thanks for asking (even if voted).



> Probably best with consistency?
>
> > […]
> the current behaviour
>
> This one, specifically.
>

I agree with Marco (who I know works on reflection-related projects).

To expand a bit:

when reading the RFC, "the notable exception that `null|false` will produce
a ReflectionUnionType instead of a ReflectionNamedType contrary to other
`null|T` types" seemed legit because
  - `T|false` currently always produces a ReflectionUnionType
  - `null|T` producing a ReflectionNamedType (like `?T`) was only decided
*for backwards-compatibility reasons* [
https://wiki.php.net/rfc/union_types_v2#reflection]
(moreover the initial RFC [https://wiki.php.net/rfc/null-standalone-type]
only proposed standalone `null`, not `false`, so didn't allow `?false`)

but now looking at the implementation, I don't like the special casing.

Regards,

-- 
Guilliam Xavier

---

## #117499 — G. P. B. — 2022-04-08T16:31:37+00:00

URL: https://externals.io/message/117477#117499 · In reply to: #117480

I have just merged the PR with the amended Reflection changes:
https://github.com/php/php-src/commit/6039c07a3afd64a42c9b9f1ed994ca971db67a1e

Best regards,

George P. Banyard
