Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109943 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13295 invoked from network); 30 Apr 2020 12:38:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Apr 2020 12:38:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 402CA1804D0 for ; Thu, 30 Apr 2020 04:11:54 -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=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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:11:50 -0700 (PDT) Received: by mail-il1-f182.google.com with SMTP id r2so923174ilo.6 for ; Thu, 30 Apr 2020 04:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=bt5h2P0kwh0s+m19EKlbx5M50DdVZXma0fjn31btalc=; b=rUpzRIlpwyMyvfVN6mN9xlICSHZTgI7lionp59pXAoz+pjs0yy32S5vXjWOjA9Xnvr Ts3Uq/14szcETWdVEV1BXba3e73xSJ0dFDyGH3S7ndLarYqkoxI1sFWIKCRC1ptHMO91 Xn+2xk3HF3ecTVKYTV/Pg0xSnRKz/kErx0+7mwNElYw2WRgx3d/Grs/ZOY4dtscrWmKR NvrN8rfKTNPEnvKbTa/wZA2k4KU9XMPjBW3zGJpCYDg4bujPQ/jjSP/R2qKL5tbUFd0g FdtDV2rhcXjv3UO1IX8rPW5hkghLKrxsGG8a2pjv1Sa/9BxZZzEfcmkADj1RIabzJHwX YaHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=bt5h2P0kwh0s+m19EKlbx5M50DdVZXma0fjn31btalc=; b=WGh3+FOtT7WO3GLDIbCkUQTLUCBDtAER0AUQudCu4svsj4OzayXyL8h0S4KdBGPlmx fRJRbs5ERe1+weTQPn/emeFFS7MINw+F1vRhVRiWIMy5AIas03ukkrnW+Nr5+0kxLtKx EzF0F3oQ1EJJvULDOQulamknFfcnqbUApKFGkYSgtheiYYTHOgCuNvw3ZbRIxmgJ0Bbr k0UaHDLRMjSpv9XuW22P78hmGY113a5AMo3ZYCBtg9geVt/rDgEwQJIZQoL4cqYDdS+Z OA9zTdYTHiZH8KK4emYiJxzWWiv5iq1bslcwBk7TAMZVIvMmIwaWak7l2McPY45TemsB 3xSw== X-Gm-Message-State: AGi0PubleQ4W5RWZcxlfJSTC44dt21uMpTlMJbih5sT3//lKc9CNTWxr B0Nm82Uib+JMh+/Nsj5pMEi17vCbCyzZg3kHhBuYR8p33FQ= X-Google-Smtp-Source: APiQypIepR8GGpWuUjtSje5bLRcT9/CU0LW1T7C5Siziv+hQj1P65hzMeqlv4mjC/UZRgHcPAlCNOKXC2m+parNggZc= X-Received: by 2002:a92:cb10:: with SMTP id s16mr1353946ilo.240.1588245106237; Thu, 30 Apr 2020 04:11:46 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 30 Apr 2020 05:11:08 -0600 Message-ID: To: Internals Content-Type: text/plain; charset="UTF-8" Subject: Ternary operator associativity From: ryan.jentzsch@gmail.com (Ryan Jentzsch) 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 $ 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