Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102748 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3877 invoked from network); 11 Jul 2018 09:20:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 09:20:13 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.214.43 mail-it0-f43.google.com Received: from [209.85.214.43] ([209.85.214.43:40400] helo=mail-it0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/63-15421-CCBC54B5 for ; Wed, 11 Jul 2018 05:20:12 -0400 Received: by mail-it0-f43.google.com with SMTP id 188-v6so2518295ita.5 for ; Wed, 11 Jul 2018 02:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=R5EvLtgKWLsmAkMW8BHhyUAi53PfeoCzM5yxTC8+ncM=; b=Q5b913uwwDZaudyHLvCwPES0yk+2cywbREEmS5jg10u21tc6fPg0U6XqtwYML93PTR 1Jf66hErefEdysGkt0h5zYQBfd+ZOuS+xEb0qx6pLpeM1p43EL6H/T9KhxkUl7WjlmK0 V/XoJo5wLFF/A8nHcGP9M6OSMjWLeYOEcmgrdD5PN7QAuli7UV6hL0wY816JutI6wkJs OGXzTW8kXCQHZkXRVlk/Lq9jQfrCxGldzMjIlPHvef7t+qoeabwJMFn4J2aYQ3hxOp9n DNdfvdaRspo4q6sE6cBRbcHcORi2eUbNyn2AYqupi7u/J+SankRZAV9DkzAEWXYkpEqE 6GdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=R5EvLtgKWLsmAkMW8BHhyUAi53PfeoCzM5yxTC8+ncM=; b=Y2BEmDwRvxwJKuXo3U0qH+RW/PtByBAeUiYHVU+UzWW8FQhZs/zz/GX+p/BDemKVwY xn8C9CoYSiMktfsaJbhhc8/3IFsrCjm8ABmbGu34HN5kWvscjJitxx6l2BWJyht2RDF+ /h/8w31OaYrTxcX5yU8alJ6e8Yws/b/KOifPFs372mOOqH3hnj/qHE8mHPQw04iiBLOW m4NRIK0X1/wtLP98AvPVLm4vC+rC6642oe/PuSSIPn/0Pym4Nd73YxmxYqvis5A1nAqZ tU73IuXUffrgxsYFIYWsJwLeFe192FH2OrbEKI8SXGdquhDEU46MQ8lA7+YTq7g7HET4 v/JQ== X-Gm-Message-State: AOUpUlETIcEuZlx2SrzuzIjvi93Gzsa60Lsiey+vvcjYH/91t3MASWwJ 2T677W+S43FDzN/LpjC8vw8a57Y2CafDU8glxGc= X-Google-Smtp-Source: AAOMgpetr/JF8oeU8VhLEFYveHKu1W9fB6Z2I0AzYv6EW8iQVXkcNyr+TiXugEsdC8qYgObikQYUBiv/O3zvWm2IosA= X-Received: by 2002:a24:4048:: with SMTP id n69-v6mr7446842ita.60.1531300809629; Wed, 11 Jul 2018 02:20:09 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:95a8:0:0:0:0:0 with HTTP; Wed, 11 Jul 2018 02:20:08 -0700 (PDT) In-Reply-To: References: Date: Wed, 11 Jul 2018 10:20:08 +0100 Message-ID: To: Ryan Cc: Michael Morris , PHP internals Content-Type: multipart/alternative; boundary="000000000000cd65dc0570b5c06c" Subject: Re: [PHP-DEV] Unifying logical operators From: rowan.collins@gmail.com (Rowan Collins) --000000000000cd65dc0570b5c06c Content-Type: text/plain; charset="UTF-8" On 11 July 2018 at 03:20, Ryan wrote: > > PHP 7 code should never be blindly upgraded to PHP 8 (which is what this > would target for actual changes, not just deprecation/notices). This would > have to be clearly stated in the upgrade guide. > There's a big difference between "not blindly updating" and "having to run a static analysis tool and carefully read its results to stop your code having a subtly different behaviour". Introducing new errors is nearly always better than silently changing behaviour (this is the entire principle of run-time type checks, after all). > On Tue, Jul 10, 2018 at 5:01 AM, Rowan Collins > wrote: > > As your own next example demonstrates, it does rely on the difference in > > precedence, because without it, you could only use this idiom after > > carefully checking that the left-hand side would be evaluated in one go, > > and probably using an extra set of parentheses. > > > > The defined or die idiom does not depend on precedence, because it doesn't > contain an assignment operator. One could theoretically do > $isDefined=defined("X") or die() - however that would be pointless as > $isDefined would always be true. > Right, which is why I said your *next* example, which did use assignment. The point is that *reliably using the idiom* requires a specific precedence, so that you don't have to carefully vet which other operators are involved in the expression. > > While I've not seen it used much in PHP code, the "do this or die" idiom > > is common in Perl (which also has post-fix "if" and "unless" modifiers, > so > > those are a different feature again). > > > > Forgive my lack of knowledge with perl, but it looks[1] like they only > support a postfix if and postfix unless operators - which can serve the > same purpose as PHP's and/or (x and y => y if x, x or y => y unless !x). > Perhaps I worded that badly. I was saying two things: - The "do or die" idiom is extremely common in Perl. Just searching the documentation should be enough to convince you of that: https://duckduckgo.com/?q=site%3Aperldoc.perl.org+"or+die" - Perl *also* has post-fix if and unless operators, which you had mentioned in Ruby (Ruby inherited a lot from Perl). Clearly, people don't see these as a better replacement for the use of "or". > My thought for aliasing is that it may help with legacy code (if you're not > relying on the return value, which is 99% of cases), as well as there being > no symbolic equivalent for xor (as you state below it's not equivalent to > != as I thought) > Just to reiterate, I strongly feel that aliasing is not an option. If the aim is to reduce confusion, having the same code give different results in different PHP versions is a massive own goal. > On Tue, Jul 10, 2018 at 2:37 PM, Kalle Sommer Nielsen > wrote: > > > > > I personally wanted to extend this syntax but I never got around to it > > to support: "do() or throw new Exception(...);", tho its just a code > > style over: "if(!do()){ throw new Exception(...); }" > > > > do() or throw doesn't actually work because throw is a language construct, > not a function. > Yes, hence "wanted to extend this syntax" - the suggestion is that this would be a useful feature to add, not one that already exists. > > A more readable syntax, if we were designing from scratch, might be to > > look at SmallTalk, where ifTrue and ifFalse are methods on the boolean > > class, so can appear post-fix after any boolean, giving you something > like: > > > > $connected ifFalse: die(); > > > > I hesitate to propose adding a new syntax to PHP, especially for something > so rarely used it makes me question if it's truly necessary. If anything I > would think we should prefer a syntax that we can point to other languages > as examples (like the if/unless syntax from Ruby). It feels odd to clean > up a rarely used operator by replacing it with fresh syntactical sugar. > I agree that adding new syntax is unnecessary for this, but since you keep mentioning the postfix if/unless which Ruby inherited from Perl, I thought I'd point to another language we could borrow syntax from, which is actually closer to the current idiom ("condition keyword action", not "action keyword condition"). Regards, -- Rowan Collins [IMSoP] --000000000000cd65dc0570b5c06c--