# Array dereferencing using alternative array syntax

- Thread: https://externals.io/message/55767
- Original archive: https://news-web.php.net/php.internals/55767
- Started by Nikita Popov on 2011-10-09T17:14:54+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #55767 — Nikita Popov — 2011-10-09T17:14:54+00:00

URL: https://externals.io/message/55767#55767

Hi list!

PHP 5.4 added array dereferencing support (e.g. `func()[1]`), but the
grammar seems to lack support for dereferencing using the alternative
array access syntax (e.g. `func(){1}`). Was this done on purpose or
was it just forgotten?

Some links:

http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#array_function_dereference
http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#array_method_dereference
http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#reference_variable
(example of grammar with alternative syntax)

Nikita

---

## #55770 — Peter Cowburn — 2011-10-09T23:30:53+00:00

URL: https://externals.io/message/55767#55770 · In reply to: #55767

Hi Nikita,


> Hi list!
>
> PHP 5.4 added array dereferencing support (e.g. `func()[1]`), but the
> grammar seems to lack support for dereferencing using the alternative
> array access syntax (e.g. `func(){1}`). Was this done on purpose or
> was it just forgotten?

I remember mentioning this on the list a while back, but didn't get
any further comment (it was an aside to a related thread).  I'd like
to see the curly brace alternative added, if only to be consistent
with the existing syntax to access array/string values that can be
used elsewhere.

>
> Some links:
>
> http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#array_function_dereference
> http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#array_method_dereference
> http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#reference_variable
> (example of grammar with alternative syntax)
>
> Nikita

---

## #55771 — Ferenc Kovacs — 2011-10-10T09:03:40+00:00

URL: https://externals.io/message/55767#55771 · In reply to: #55770

> Hi Nikita,
>
> 
> > […]
>
> I remember mentioning this on the list a while back, but didn't get
> any further comment (it was an aside to a related thread).  I'd like
> to see the curly brace alternative added, if only to be consistent
> with the existing syntax to access array/string values that can be
> used elsewhere.
>
> > […]

hi, thanks for bringing this up.
the alternate syntax has a rough past (if I remember correctly, [] was
mentioned to be deprecated, then with 5.3 the preference was switched:
[] is the preferred way now, and {} got almost deprecated), so if we
plan to support the {} syntax on long term, I'm +1 for adding this to
the language.
I we plan to remove it eventually, then imo it is better to not
introduce the support for the alternative syntax.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #55772 — Nikita Popov — 2011-10-10T09:55:48+00:00

URL: https://externals.io/message/55767#55772 · In reply to: #55771

> the alternate syntax has a rough past (if I remember correctly, [] was
> mentioned to be deprecated, then with 5.3 the preference was switched:
> [] is the preferred way now, and {} got almost deprecated), so if we
> plan to support the {} syntax on long term, I'm +1 for adding this to
> the language.
> I we plan to remove it eventually, then imo it is better to not
> introduce the support for the alternative syntax.
Imho it should be supported regardless of whether we want to remove it
or not - for the sake of consistency. I'm all for getting rid of the
alternative syntax (especially because it gets more and more
convoluted as the language evolves: you might still understand
$str{1}, but func(){1} looks more like some strange lambda than a
string offset access), but I think that for the several years that we
will definitely still support the alternative syntax (as removal of
features in PHP usually takes decades) it should be supported fully.

Nikita

---

## #55773 — Pierre Joye — 2011-10-10T10:02:20+00:00

URL: https://externals.io/message/55767#55773 · In reply to: #55772

hi,

On Mon, Oct 10, 2011 at 11:55 AM, Nikita Popov
<nikita.ppv@googlemail.com> wrote:

> Imho it should be supported regardless of whether we want to remove it
> or not - for the sake of consistency.

If we ever want to have a consistent syntax, then no, we should not
add it and only support the consistent syntax in new additions.

Cheers,
-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #55778 — Nikita Popov — 2011-10-11T14:35:25+00:00

URL: https://externals.io/message/55767#55778 · In reply to: #55773

> On Mon, Oct 10, 2011 at 11:55 AM, Nikita Popov
> <nikita.ppv@googlemail.com> wrote:
>
> > […]
>
> If we ever want to have a consistent syntax, then no, we should not
> add it and only support the consistent syntax in new additions.
You may have a point there.
But last time the alternative syntax was discussed it was decided to
keep it, so probably the dereferencing support should be added for it
too. Or do you want to discuss the removal of the syntax another time?

Nikita
