Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105225 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4451 invoked from network); 11 Apr 2019 00:33:27 -0000 Received: from unknown (HELO mail-it1-f180.google.com) (209.85.166.180) by pb1.pair.com with SMTP; 11 Apr 2019 00:33:27 -0000 Received: by mail-it1-f180.google.com with SMTP id y204so6057364itf.3 for ; Wed, 10 Apr 2019 14:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=y0VpHhBz3rWyb8hU/i6Ud6Z/Ezh8IeLLSeBQILGFjgY=; b=nXXxqTy3XUSrMc7ERHkNvJug/mkA/ywJdlWteE8TUpm+dnQp31KIdRWxFx5lHbMt2E TmMQoPFqXXdJNOt2lbrGWiExHoWV1w63x1CxniJkKLT5zVrklSUZk0j/VIqDBZIgEzBU 6HuW9rn4eyPKSzSCPakXxjxxgI9VYa/NW5ZkkH/MK62XY1gOK0G20Pu2y+O/pKh8c1i9 Jrn6nv2ZhvOCRkxFHHF5Ib4EwlyeM6skguZ0e7cKIA9QTze4lIa0lId6dxCQnQgbgl8w xVQPL+kjD7TaW5DBsAC94hI2GbyfrzA8nCycntfWVbf+CSZPsm7mF+y2pDYsqAnI7KTP oRDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=y0VpHhBz3rWyb8hU/i6Ud6Z/Ezh8IeLLSeBQILGFjgY=; b=K622Fc7UPMqcu7NBtwxQJmkdRycjhIyBOiXEmxoJOSNSdnLmKvyyudZoaIk7Hffb9o C1er7WXx8w1KxE9WeokSqlwtfRsFcbdzHDIAAv6GR/9stNIFE2qxifSbrWrEP09uuK34 T1BdYsqA5ndNIRn6I80Ozj2ClhDsiyiNloLyW0BtLBQ5JLXIv4iMuXvTni88O7o1u+q5 Tu69qILo9Ii8WOAXNfwFKZKu0krKjkPj5m8CFjAraIalmk7fW7u/B6MxAO13mHgECnUP KgSWzzayha+rTY0IY7MChCiK41lwTG8660c1X6Zdb3dBiCXFZwDRT01QFYqf0zp4gLsg nuQw== X-Gm-Message-State: APjAAAWX3xjPjOrsmlbj5XTqykvrNCemIb2ZokwPEHDtqD8/B4impSHo +eSIRnI5xBMiuP2CMzqjMKG/f9G5xv9xeVtQmdI= X-Google-Smtp-Source: APXvYqy3uMpHz1+nfrTLJMIOZeTZHwSBfSP4Sg7RBurKTJsZ7uGDycUxChPUQ10LC+TeIO4IrdA2bHRfq4YstlP+TDA= X-Received: by 2002:a02:9f93:: with SMTP id a19mr32177050jam.123.1554931840709; Wed, 10 Apr 2019 14:30:40 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <5cae2f86.1c69fb81.ce442.006eSMTPIN_ADDED_MISSING@mx.google.com> Date: Wed, 10 Apr 2019 23:30:28 +0200 Message-ID: To: Mark Randall Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000003f976058633c8d6" Subject: Re: [PHP-DEV] [RFC] Nullable Casting From: benjamin.morel@gmail.com (Benjamin Morel) --00000000000003f976058633c8d6 Content-Type: text/plain; charset="UTF-8" > That's exactly what it is, and thanks to null coalescence, you then have > an easy available ability to either check if it succeeded, or default to > another value. 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. - Ben On Wed, 10 Apr 2019 at 20:01, Mark Randall wrote: > On 10/04/2019 18:34, Benjamin Morel wrote: > > So why would you have different semantics for implicit `(?int)` cast vs > `: > > ?int` function return type cast, if they're both *out*? > > Return type cast has the same semantics as parameter type cast. > > I would have to disagree with this as I think of "return" as a language > construct function that takes one argument. When a return type is > specified, that return function effectively inherits that type for its > only argument, and limitations on implicit conversion should apply. > > > This looks weird to me. I would expect this last line to throw anyway. > > Having "foo" passed somehow where your code expects an int(ish) or null, > > should not be silenced and converted to NULL IMO. > > To me, this last line just says "ignore any error here" - a bit like > > prefixing it with @. > > That's exactly what it is, and thanks to null coalescence, you then have > an easy available ability to either check if it succeeded, or default to > another value. > > $items = (?int)$_GET['items']; > if ($items === null) { > // it didn't just resort to 0, which might be perfectly valid > throw new Exception('Unsure how many items'); > } > > $value = (?string)$_GET['name'] ?? ''; > if ($value === '') { > // also, ?name[]= can sod off > throw new Exception('You must provide a name'); > } > > -- > Mark Randall > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --00000000000003f976058633c8d6--