Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105229 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34914 invoked from network); 11 Apr 2019 02:48:01 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 11 Apr 2019 02:48:01 -0000 To: internals@lists.php.net References: <5cadfed8.1c69fb81.31f7d.1c49SMTPIN_ADDED_MISSING@mx.google.com> <5cae100d.1c69fb81.548c.48a4SMTPIN_ADDED_MISSING@mx.google.com> <5cae1fec.1c69fb81.d2407.c20eSMTPIN_ADDED_MISSING@mx.google.com> <5cae2f86.1c69fb81.ce442.006eSMTPIN_ADDED_MISSING@mx.google.com> Date: Thu, 11 Apr 2019 00:45:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Posted-By: 94.0.205.114 Subject: Re: [PHP-DEV] [RFC] Nullable Casting From: markyr@gmail.com (Mark Randall) Message-ID: 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