Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107615 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38014 invoked from network); 21 Oct 2019 22:47:58 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 22:47:58 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id AD36C2D2001 for ; Mon, 21 Oct 2019 13:33:42 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-yw1-xc35.google.com (mail-yw1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 21 Oct 2019 13:33:41 -0700 (PDT) Received: by mail-yw1-xc35.google.com with SMTP id o195so583322ywd.8 for ; Mon, 21 Oct 2019 13:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=gY46zSizAAFNEgPeJXbFAgxWKnjNQ1e2K+w05NF0BZY=; b=0ExkQsivKKnYVmHLMiTKXr2kOsUyqAglSpnOexOxjoU1yKYMym2J7BRWWBcX4/nNUB Is6+2+rLcDK6Cr34Na6ZJXsrRuKaNiZ7zYtvVLuuUxDgn2DQE0BascpiTttEyxcXTW46 HkGHgf1bJ1yknvq2cY5da/fzpUm+LW06l7xHvLZT8HknPkWzbCkx8MmakjDuCTexQnAo WmlC2uw3MkxiZFlKB7qZu6z0/yCTxYqj8ZEjNjfPK9qffU0rvqyidsqbxsYgkNGElL4T W+WOVWQ+JUfpYNHHPBM36/4jTQ+pjzjmmwJr9V5g59pH1ln6h3atM2oz3ZOcT+UBMdMM U/CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=gY46zSizAAFNEgPeJXbFAgxWKnjNQ1e2K+w05NF0BZY=; b=JPsSUG+whtuG0CdSLvSLC5RW2SRAfK29ohHt/3ohvCzwfdK4uf8WTECtD2sTRrbdwN GMNl8YQTLc9Ve6T0eUpeg6uFED5VR4hbv+8ufL9ql2PXsYH1dKe/B9QdKk1iZP/Gv9Kj I60O0tmV/uLt28QLrXZzjYqmjjflRUQqI0K0VWxMSN+SEbObrlQ/4WkF3hjitKGlLt7i 7znlFgPdPRmc6ozUlt6F1Dgdxez8VXILYNTZwNqc2TrULGK1gihO9gadMlDEl4eEV9I0 gmXGFUO926BhVoLuXO5iVqGC21a3S2Fr1UQDAreM94Lqs5ubl+wVvA4KtdOZG/d9VtBX uiXw== X-Gm-Message-State: APjAAAVHVjRb50OZc8xmI9X5NJaV88ElqUXg2HTWFVI+7vIY02qrAyxp jmYHzDg4jmRWh9yjdp27VVY8mQ== X-Google-Smtp-Source: APXvYqzoO7ewH06F/Z4AwbXL319NgAkPNWaE0JRE2k3JnWPaHxfPhTsIw8BRQvKnWovFmyIhRF1UXQ== X-Received: by 2002:a81:9807:: with SMTP id p7mr578017ywg.370.1571690021310; Mon, 21 Oct 2019 13:33:41 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:31a1:4ef0:57ff:9f9? ([2601:c0:c67f:e34e:31a1:4ef0:57ff:9f9]) by smtp.gmail.com with ESMTPSA id s24sm509390ywa.92.2019.10.21.13.33.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 13:33:40 -0700 (PDT) Message-ID: <17D060DE-C095-400A-862C-5231B86104C6@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_A655A939-DA74-4AA3-8C20-74600FAC6043" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 21 Oct 2019 16:33:40 -0400 In-Reply-To: Cc: PHP internals To: Rowan Tommins References: <91095002-BA0D-440B-8FAB-AA003A0EDB69@newclarity.net> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_A655A939-DA74-4AA3-8C20-74600FAC6043 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Oct 21, 2019, at 4:51 AM, Rowan Tommins = wrote: >=20 > On Sun, 20 Oct 2019 at 22:35, Mike Schinkel = wrote: >> I would much prefer to use a switch for multiple, mutually exclusive = cases >> no matter what how complex the expression is because with a switch = the >> cases expressions line up vertically. With `if` and `else if` it is = harder >> to vertically eyeball the different mutually exclusive cases. >=20 > I've never particularly been bothered by it, but wouldn't adding four > spaces in your "if" statement make it line up with all your "elseif" > statements? Possibly, but then again I am: 1) Mostly reading other people's code who will not have formatted their = IFs that way, and=20 2.) Using a code reformatter to standardize code format via my IDE and = there is no option for that. As for #1, I know I cannot enforce switch usage outside my own team, but = at least for own team our standard says "use switch for multiple = expressions" when possible so at least it would provide we can have = consistency across our team. >> But how often will we have this use-case? Only for global variables, >> which hopefully will eventually become extinct in userland code. >=20 > Not just global variables, no;... Fair point. >> That said, we should almost be able to do *both*, and just let PHP = throw >> an error if there is a problem. This would be useful if you know 100% = that >> the code won't fail because of the code that came before it: >>=20 >> if ( is_numeric($_GET['id'] ?? 0 ) ) { >> $id =3D intvar($_GET['id'] ?? 0); >> $user =3D getUser($id): >> } >=20 > I'm not sure what the point of this example is. You've just cast to = int, so > the assertion can never fail, and if getUser has a type hint, it's = about to > make that assertion anyway. Yeah, I know. I could not come up with a great example on the spot. I'll have to go off and do some more coding because that's when I always = come across the good examples. Which is usually not the same time I need = the good example. :-( -Mike= --Apple-Mail=_A655A939-DA74-4AA3-8C20-74600FAC6043--