Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96723 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61444 invoked from network); 3 Nov 2016 16:04:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Nov 2016 16:04:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.65 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.218.65 mail-oi0-f65.google.com Received: from [209.85.218.65] ([209.85.218.65:35363] helo=mail-oi0-f65.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/7D-34238-3FF5B185 for ; Thu, 03 Nov 2016 11:04:03 -0500 Received: by mail-oi0-f65.google.com with SMTP id v84so7401891oie.2 for ; Thu, 03 Nov 2016 09:04:03 -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; bh=hceTeg24DqTPRO1sUSsHwhN6tm3TjkByALz63gHpE5s=; b=g/WrwhqbztFiWwgEXSNf9HlajI7uK1irV8gbVsOgeX8LlQEFcA6FuhxAhtw90vrtJ/ PVFlYEBrqS/QnlfWckpBL6fRzI78vUwLTDfc2X+wywTmYAxaDsMcVtJZ3wcQybCkkKb0 uTmMYbBQcRTVdkCW+KmLTuJxe7/X3IKnaVk/xtyGO2CfwLytFwhl4x6u2+KWgZOB6SGq y9QID2cOEyMD6iV2V36UbRfkT0y+KsCAMV83s104ljLNt1j27yTVxmneVQ0cUEe0wOg6 l95EgbNNvqQe9sYB1SpZlpBu6liLbHHTErJXiaRDGFci9U5efh5jSGKHvUtr+e/vFuT+ jjDw== 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; bh=hceTeg24DqTPRO1sUSsHwhN6tm3TjkByALz63gHpE5s=; b=J5fotXEYrQYyhCc7OHrdDfn8MBhuf2DMocsudO2yShTvpz84EyNZboxBaZJhpMXcGt lEjTJiFSomB7kUqeBkLI/3LTpHg+JKRQd8rTR6VvjS3xCmajDZr69yGaG4pvk+ABlzNj JqdaEVgRrXhHYY0oKrd/eUnoPBXLE5rLAgpWyNvXgx5mivan7PQrn/bQlHV0A4KRPDPG RdeFomMc7BVNSPxWL9lH1sR/uFa2dnJdAhSIilLYMRPSEUSJ1RdDwd9JmXjNGLjLsq/z 5AhtqMgsDmFsOWRCecQiVEGUII0acyzJwVkR80kfGt/TBvOMujzP7vNMnsR7tUsTiZD5 SIIw== X-Gm-Message-State: ABUngvdxCuIaXhopSUHU0eqrq7K11/lM93k64IFo+VxkpHsbjB55VPqFcwu2zcjfIVXQIJ0LX9kvQ0JRMLnWcg== X-Received: by 10.107.12.148 with SMTP id 20mr9030133iom.208.1478189040593; Thu, 03 Nov 2016 09:04:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.142.148 with HTTP; Thu, 3 Nov 2016 09:03:40 -0700 (PDT) In-Reply-To: References: Date: Thu, 3 Nov 2016 14:03:40 -0200 Message-ID: To: "Antony D'Andrea" , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Proposed RFC From: david.proweb@gmail.com (David Rodrigues) > Yes I have but I would like it to return ($n1/$n2) or whatever this input is, without repeating it again. But it should do exactly that, except for a falsy return (eg. zero, empty, null, false) - note INFINITY is a truth value, so 10/0, for instance, will return INF instead of "else value". For instance: $n1 = 10; $n2 = 5; echo ( $n1 / $n2 ) ?: 'ELSE VALUE'; // Will returns 2 $n1 = 0; $n2 = 5; echo "\n"; echo ( $n1 / $n2 ) ?: 'ELSE VALUE'; // Will returns ELSE VALUE 2016-11-03 13:56 GMT-02:00 Antony D'Andrea : > Hi, > > Yes I have but I would like it to return ($n1/$n2) or whatever this input is, without repeating it again. > ________________________________________ > From: David Rodrigues [david.proweb@gmail.com] > Sent: 03 November 2016 15:48 > To: Antony D'Andrea > Cc: internals@lists.php.net > Subject: Re: [PHP-DEV] Proposed RFC > > 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 -- David Rodrigues