Re: Implicit isset/isempty check on short-ternary operator
| From: | Adam Richardson | Date: | Thu, 14 Apr 2011 14:58:57 +0000 |
| Subject: | Re: Implicit isset/isempty check on short-ternary operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51903@lists.php.net to get a copy of this message | ||
On Thu, Apr 14, 2011 at 10:05 AM, Hannes Landeholm <landeholm@gmail.com>wrote:
> Trying to summarize this discussion... I think we can all agree that the
> main problem is "code duplication for array access when parameters are
> possibly not existing". I think we all can also agree that @ can be both
> used properly and misused - and it is a blunt tool and not a nice solution
> to the previously stated problem.
>
> Some suggested that the ternary if comparison should suppress the notice
> automatically. This would break existing code and also be confusing since
> people expect a ternary if and normal if to work the same way.
>
> Some suggested ?? as an array access operator that suppresses the notice
> and
> has 3 variants: A: nothing specified - uses null as default, B: has default
> specified, C: returns X if index exists or Y if index doesn't exist. This
> effectively solves the code duplication problem and is a shortcut for
> saying
> "the array index may or may not exist".
>
> One person said that the relation between ? and ?? and == and === would
> make
> the operator non-intuitive. Other people disagreed and claimed the
> opposite.
>
> So basically the discussion now is what exact characters that should be
> used
> to represent this operator? I really hope we can get this implemented
> quickly... I worked with $_POST yesterday and I could really use that ??
> operator.
>
> ~Hannes
>
There was also my suggestion of a "checked ternary" operator [see my
previous email in this thread.] Backwards compatible, practical, and simple.
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com