On 10.11.2023 12:11, Kamil Tekiela wrote:
function abc(string|int $p) {}
abc(null);
What should null be converted into and why? If you as a developer know then
you can cast the argument to an appropriate type but on the language level,
it's not really possible.
So, in conclusion, we are not supporting you because we are stubborn or
that we want to force strict types, but because resolving this problem in a
way you want is extremely difficult and borderline impossible.
Then throw an error when it is not possible, but in most cases it will
be, I assume.
Why strtoupper(0) works but strtoupper(null) throws a warning? The
argument is defined as string, so the former should be a warning too, if
we were to be consistent. It's a rethorical question, I know arguments
of both sides.
As OP, I think that this behavior should be controlled by strict types.
I.e. in strict_types=1 throw an error, in strict_types=0 use null
coercion if possible (w/o warnings).
Of course, the inconsistency/confusion can be fixed in different ways,
but what's proposed here is best for BC reasons, imo. Other options
would make the language more strict.
That being said, I'm also aware that currently, most likely, none of
such proposals would get 2/3 of votes.
--
Aleksander Machniak
Kolab Groupware Developer [https://kolab.org]
Roundcube Webmail Developer [https://roundcube.net]
----------------------------------------------------
PGP: 19359DC1 # Blog: https://kolabian.wordpress.com
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php