RE: [PHP-DEV] Proposed RFC
| From: | Antony D'Andrea | Date: | Thu, 03 Nov 2016 16:11:56 +0000 |
| Subject: | RE: [PHP-DEV] Proposed RFC | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96725@lists.php.net to get a copy of this message | ||
Thanks everyone for your responses.
It has not taken long to find situations where this idea starts to fall apart. For example, in the
case of strpos, I would hope for the return value, but in other cases I would want the the original
input if the output is not false.
That makes this feature pretty unfeasible I think!
________________________________
From: bishop.bettini@gmail.com [bishop.bettini@gmail.com] on behalf of Bishop Bettini
[bishop@php.net]
Sent: 03 November 2016 16:02
To: Antony D'Andrea
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Proposed RFC
On Thu, Nov 3, 2016 at 11:02 AM, Antony D'Andrea <contactme@antonydandrea.com<mailto:contactme@antonydandrea.com>> wrote:
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.
Welcome!
Let me read back what I'm hearing. If the predicate returns truthy, you want to return the
argument to the predicate, otherwise the indicated default?
How would this be used outside predicates, such as on string functions?
Consider: echo strpos('abc', 'b') ?! 0;
What would this output, and what would the purpose of such a construct be?