Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109944 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14931 invoked from network); 30 Apr 2020 12:41:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Apr 2020 12:41:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 003B41801FD for ; Thu, 30 Apr 2020 04:15:12 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 30 Apr 2020 04:15:11 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id f8so857255lfe.12 for ; Thu, 30 Apr 2020 04:15:11 -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=P2mtrx/VghT6Wx0ptd+0u6L/MDsC5AzhbxpS20Pg7Es=; b=EELk8qzN9g8vyOKJDFv86GEOpu2WPELTu5Dr8s/yx63u5wKBEmz+j+BgHUZa0AXeyL w63Ylk9Ps7CHWB38nELmGouun0f3Q8iEGw5D2TOA/0HBThZFx8KFe9Ik6y2ZH/sOz0Ue 0A9y8FAytUKUtU6yj6gyZ/vVn8owyQ0KQ8viu6iXv6Z2Qs8zuL7cQyVzgSBLg1CGMUe5 toqy6jARlaPRTKg0juQY0Vq7/Q5kpda0R7MRzxzjoXgPH888m1huiGGCMnMzfYpLGRk/ eRNj5LYrHEiaJA1tSS2iKg0iayiZ6XWhetXiUg4ycUorrQGBZKV7DpTRag2BoOPyImTh AVEg== 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=P2mtrx/VghT6Wx0ptd+0u6L/MDsC5AzhbxpS20Pg7Es=; b=OWHVCDp6mn3vdlsE45WnYvKpkDsp6uHohMBb4BpwivF0TBXwFPwCI7ARmk+e7uh42Q Agh5BTP4IxLg/NInyxqr0oTYhyapxoxp50yycP3dyY72T4tClCWm/5nXwccFaaO8BJf4 HCxPm3ni7vWPcUi3Jhq836MVwizn2hWmSALXcRQRBG1X27ZoIEzqh5S80ZBKMXaOj/6M k8QaILxSTte27UOTmQPnP2jHQeThuoN3M0Ei97HdLeX8mLzdVJOnHctX7n1Q+9Lwbt+L jvX0f/CSi6OVARyF2QrH0On9IIUhBWYil0y4w7N1BZfLx4lvsw8Y4/f2lDbs7HcYerEC r89Q== X-Gm-Message-State: AGi0PuZY3MSabUCRgAa2zdX2LU03vb/WnDz+7obkOokuCgEQmMOSktG3 Z4CFDtTqUWr2bovcZhBt7A1ayOHMWPVd10zap58= X-Google-Smtp-Source: APiQypKPCVJdIZLEkeAsd1xPXzSekR+t5lLeCE6zHRbcEeU4O5GknlSl5qSKdRVSn7ddzgiG5e/kIh1tfhoyotXzT1o= X-Received: by 2002:a05:6512:242:: with SMTP id b2mr1861403lfo.92.1588245309777; Thu, 30 Apr 2020 04:15:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 30 Apr 2020 13:14:52 +0200 Message-ID: To: Ryan Jentzsch Cc: Internals Content-Type: multipart/alternative; boundary="000000000000816f9305a4802d79" Subject: Re: [PHP-DEV] Ternary operator associativity From: nikita.ppv@gmail.com (Nikita Popov) --000000000000816f9305a4802d79 Content-Type: text/plain; charset="UTF-8" On Thu, Apr 30, 2020 at 1:12 PM Ryan Jentzsch wrote: > Is there a possibility this can be fixed in version 8? From > http://phpsadness.com/sad/30 listed as an outright bug (I don't have > the C skills to fix this. I am just raising this as an issue that has > been a criticism of PHP for many years now with a new major version > upcoming that could allow for a b/c of this significance to improve > the language): > > The ternary operator is left-associative and therefore behaves > entirely incorrectly: > > $ cat ternary.php > echo (FALSE ? "a" : FALSE ? "b" : "c")."\n"; > echo (FALSE ? "a" : TRUE ? "b" : "c")."\n"; > echo (TRUE ? "a" : FALSE ? "b" : "c")."\n"; > echo (TRUE ? "a" : TRUE ? "b" : "c")."\n"; > ?> > > $ php ternary.php > c > b > b > b > > In any other language with a ternary operator, you can stack them and > build an if-elseif-elseif-else expression: > > $ cat ternary.pl > #!/usr/bin/perl -w > use strict; > > print +(0 ? "a" : 0 ? "b" : "c")."\n"; > print +(0 ? "a" : 1 ? "b" : "c")."\n"; > print +(1 ? "a" : 0 ? "b" : "c")."\n"; > print +(1 ? "a" : 1 ? "b" : "c")."\n"; > > $ perl ternary.pl > c > b > a > a > Please see https://wiki.php.net/rfc/ternary_associativity. Regards, Nikita --000000000000816f9305a4802d79--