I don't think that would actually be wise. Automatic casting of null to
other types is a handy feature and deprecating it brings no benefit to
anyone.

Instead, if you want, submit a proposal to reverse the direction. Make it
so that null is cast to an appropriate type in params and return values.
This should only apply in loose-type mode and it would make nullable types
useless. Such a change could also be complicated to implement given how
ambiguous it would be. But if you can outline tangible benefits and write a
PR to show how it would work, I think the community would review the RFC.

But as I expressed before, the current path seems to be the most logical.
Despite the decision to introduce nullable types in PHP 7, which as you
pointed out creates an incompatibility with all other type juggling rules,
this is the cleanest and least ambiguous solution.

As for the negative responses, it's probably because it's been many PHP
versions since the nullable types were introduced. People accepted it and
are generally satisfied with how it works. Only after the last bit was
decided to be fixed in PHP 9.0, you started a discussion pointing out that
on paper it's misaligned with other parts of the language. Just because
null is converted to string in one context and throws an error in another
is not necessarily a bad thing. So unless it's causing some serious
problems for PHP developers or users, I think it's too late to change the
design of the language.

Regards,
Kamil

Reply via email to