Re: [RFC] Nullable Casting
| From: | Claude Pache | Date: | Mon, 08 Apr 2019 16:17:19 +0000 |
| Subject: | Re: [RFC] Nullable Casting | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105151@lists.php.net to get a copy of this message | ||
> Le 8 avr. 2019 à 07:05, David Rodrigues <david.proweb@gmail.com> a écrit :
>
> And about "settype($variable, "?int")" it was requested on original mailing
> by Claude Pache.
PHP has several ways to perform casting:
1. (int) $foo
2. settype($foo, 'int');
3. intval($foo)
They are occasions where the programmer will prefer one method to the other. For example:
1. foo((int) $bar)
2. settype($someNonTrivial[$expr]['ession'], 'int');
3. array_map('intval', $foo)
The
intval($foo) family of functions might be replaced by function ($foo) {
return (int) $foo; } (or maybe soon by fn($foo) => (int) $foo), so that it
might not be a necessity to double them with intvalIfNotNull($foo), etc. functions
(also, finding a good name is not evident). But as for settype(), it cannot be replaced
by casting syntax in case the target type is not written literally in source code; so that we should
continue to fully support it. (And see https://externals.io/message/103779#103805
<https://externals.io/message/103779#103805>
for real world usages.)
—Claude