FAQ
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

Search Discussions

  • Peter Cowburn at Oct 9, 2011 at 11:31 pm
    Hi Nikita,
    On 9 October 2011 18:14, Nikita Popov wrote:
    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.
  • Ferenc Kovacs at Oct 10, 2011 at 9:03 am

    On Mon, Oct 10, 2011 at 1:30 AM, Peter Cowburn wrote:
    Hi Nikita,
    On 9 October 2011 18:14, Nikita Popov wrote:
    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.
    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
  • Nikita Popov at Oct 10, 2011 at 9:55 am

    On Mon, Oct 10, 2011 at 11:03 AM, Ferenc Kovacs wrote:
    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
  • Pierre Joye at Oct 10, 2011 at 10:02 am
    hi,

    On Mon, Oct 10, 2011 at 11:55 AM, Nikita Popov
    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,
  • Nikita Popov at Oct 11, 2011 at 2:35 pm

    On Mon, Oct 10, 2011 at 12:02 PM, Pierre Joye wrote:
    On Mon, Oct 10, 2011 at 11:55 AM, Nikita Popov
    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.
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedOct 9, '11 at 5:14p
activeOct 11, '11 at 2:35p
posts6
users4
websitephp.net

People

Translate

site design / logo © 2021 Grokbase