On 15/04/11 12:05 AM, Hannes Landeholm 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".

For me the problem is 'code duplication when a value might be null'
(whether an array, variable or something else, and regardless of whether
it was set to null, or not defined at all).

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.

Yes.

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.

Yes.

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".

This only works if the test is made an isset() kind of test. If it
remains a boolean cast, it doesn't help much. (Or at least it doesn't
help me much.)

I also think it's a bit too blunt. In all but the simplest expressions
in the condition, desired notices could be silenced. I like the idea of
being able to specify exactly which array lookups should be silenced.

It also doesn't help the people who want an isset() style test, but
without the notice suppression, and I think there are a few people in
that category.

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.

I still don't think we've reached agreement on exactly what we need.
Your summary seems to me to be of some of the earliest and least
developed ideas. I think the discussion has moved in a number of
interesting directions since then and we should draw on that later work.

Ben.




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to