On 10/04/2019 22:30, Benjamin Morel wrote:
Your arguments are perfectly valid and make sense, I guess this is a matter
of not viewing different semantics for explicit and implicit cast as
inconsistencies.
It's an interesting discussion and I appreciate you engaging on it.
I wonder, perhaps, if the goals of your initial RFC could be achieved by
a single operator?
If your intent is to pass through null and convert everything else, then
it seems to me what you're really after is a reverse null coalescing
operator, a binary operator that takes the right hand side only if the
left hand side is not null, although I'm struggling to think of any
character combination to represent it.
Although you have to write the variable twice, it seems more generic...
Admittedly I'm unsure which real-world cases it would be relevant to.
$nullable_number = $maybe_null ^?? (int)$maybe_null;
Personally I would have maybe approached it a different way and changed
casting itself to contain an ordered list, where the first convertible
match is returned.
$nullable_number = (null|int)$input;
$input is null, null is a legit cast to null, so matches first condition
and returns null. Otherwise moves on to next option and casts it to an
integer.
--
Mark Randall
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php