Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96721 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58518 invoked from network); 3 Nov 2016 15:48:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Nov 2016 15:48:43 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.67 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.218.67 mail-oi0-f67.google.com Received: from [209.85.218.67] ([209.85.218.67:33408] helo=mail-oi0-f67.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/DC-34238-A5C5B185 for ; Thu, 03 Nov 2016 10:48:43 -0500 Received: by mail-oi0-f67.google.com with SMTP id x4so7362340oix.0 for ; Thu, 03 Nov 2016 08:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=V2goQJMmU3VemjgpEReWNPvfL50PnMxPjE93qr5RR7M=; b=vZtI/tbcPaN1hWRaorQPqRbU5DHyjycDEXfohMv2b/eYSNdrW/zS87EbTcjUejxGus 3MXV86CxfvergFUF8+JCCHbdLl7E5KXCaaxHEeVTewxpKdObTF0+/A9FWAMNpRqMlqgo 91EmW88DLLXTixUKIvzQVDwa6H4FPnjEg/I6Wzn1srvgkTISJ8gy7NGtLWjYHeC0/UG3 TL9gQE293jNl/x/ykRxDOw4IyuYbZuL4iW//KE/zFmR+B/dd5ObJpPxkEpxxZAkRHqj9 nCmOg31j0sDJ2L7MbrNS1O9SW3Vr25nwpdpZtGWoFksivGIHDWZCPeOQjleCcxXGFFJu cEOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=V2goQJMmU3VemjgpEReWNPvfL50PnMxPjE93qr5RR7M=; b=gbc3vNifINsoTuLIOZQgYRaCRbwqmyaF8rdu7pK4sA2ReHrNbafcYLbeDhB6qqf6KH hSyHQcG8QC4Q/iTljh2dipHG7UOHsMz/Tlt02vHWAv0oV5VRUMRWme83XndWdl3nnr9a 1FFsGUOEEu/UEUsaraZ+kfT7yyWoSSUsVW7DhmOXdSl4kCO8FDQJA+KZb44bu9iIMXe7 EguZNzF6J3L44hpYGOSoBbwjD77rFD+5ZA9Yrjk7QxzCh8kaIU2eX3y+tOPWS4dmVljV sNosZK1rUSs7AN3uHzsAbmrayUrcvw3TSPdgqoMMLASTEcGJCOYPdfU9MhG785HVXDl/ 1Xzg== X-Gm-Message-State: ABUngvevSs+ktYi5ELm0+z8aiEkpRZr/s+8RzwoPkg+xiHlspto0o5s6pXf4JtJfSIVqxa1lFqlmESsP8Me97Q== X-Received: by 10.36.139.4 with SMTP id g4mr5735230ite.35.1478188119432; Thu, 03 Nov 2016 08:48:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.142.148 with HTTP; Thu, 3 Nov 2016 08:48:18 -0700 (PDT) In-Reply-To: References: Date: Thu, 3 Nov 2016 13:48:18 -0200 Message-ID: To: "Antony D'Andrea" Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Proposed RFC From: david.proweb@gmail.com (David Rodrigues) You have tried the ?: operator? echo !is_infinite($n1/$n2) ?: 0; It should returns true or 0, for this case. 2016-11-03 13:02 GMT-02:00 Antony D'Andrea : > Hi all, > > First off, this is my first time e-mailing internals or even thinking about submitting RFC. Please forgive me if I fail to follow some kind of convention. > > In PHP 7.0, we were given the Null Coalesce operator. For example: > > echo $array['key']??"key is not set" > > would be the same as: > > echo (isset($array['key'])?$array['key']:"key is not set" > > This is a great feature, that makes code much cleaner. > > This works on the principle that "$array['key']" is "NULL". > > I would like to propose a new feature that is as clean as this but is a slightly different use case. This would require a new operator (up for discussion, but an early idea is "?!") For example: > > echo (!is_infinite($n1/$n2)?!0); > > Would output ($n1/$n2) if it is "true" and 0 if false. > > Right now, the closest we have to this is ?: operator. The problem with this is that it could get very messy as you still have to do: > > echo (!is_infinite($n1/$n2)?$n1/$n2:0); > > I have obviously over simplified the example. You wouldn't have a big problem in this case, but if the subject of the function is much longer, it can become complicated very quickly. > > Alternatively, a perhaps more general feature would be to just have the same functionality as the Null Coalesce, but with true/false rather than Null/Not Null. > > Please let me know if there is something in these ideas or anyway to improve them. I should also note that I would need a volunteer to implement this as my "C" skills are non-existent and I wouldn't have the confidence to delve into the the PHP source. > > Thanks for your time. > > Best, > > Antony D'Andrea -- David Rodrigues