FAQ
hi guys. i'm very new to your list so maybe something similar to my
proposal has been already posted somewhere at this list but really i
don't know how i can make the search.
i often pass arrays to functions/methods this way:

myfunc(array('key1'=>'val1', 'key2'=>'val2', ...));

it's really annoying to type in 'array' every time. i suggest using a
simpler syntax:

myfunc(['key1'=>'val1', 'key2'=>'val2', ...]);

like in javascript. it'd be very nice to have this handy feature.

regards,
jay

Search Discussions

  • Jeff Griffiths at Dec 18, 2008 at 12:37 am

    On 12/17/08 4:29 PM, jay wrote:
    hi guys. i'm very new to your list so maybe something similar to my
    proposal has been already posted somewhere at this list but really i
    don't know how i can make the search.
    i often pass arrays to functions/methods this way:

    myfunc(array('key1'=>'val1', 'key2'=>'val2', ...));

    it's really annoying to type in 'array' every time. i suggest using a
    simpler syntax:

    myfunc(['key1'=>'val1', 'key2'=>'val2', ...]);

    like in javascript. it'd be very nice to have this handy feature.
    This has been discussed as a potential feature for 5.3, but was
    discussed after no small amount of flames and acrimony. here is the
    relevant wiki page:

    http://wiki.php.net/rfc/shortsyntaxforarrays

    cheers, Jeff
  • Jay at Dec 18, 2008 at 1:18 am

    On Wed, 2008-12-17 at 16:37 -0800, Jeff Griffiths wrote:
    On 12/17/08 4:29 PM, jay wrote:
    hi guys. i'm very new to your list so maybe something similar to my
    proposal has been already posted somewhere at this list but really i
    don't know how i can make the search.
    i often pass arrays to functions/methods this way:

    myfunc(array('key1'=>'val1', 'key2'=>'val2', ...));

    it's really annoying to type in 'array' every time. i suggest using a
    simpler syntax:

    myfunc(['key1'=>'val1', 'key2'=>'val2', ...]);

    like in javascript. it'd be very nice to have this handy feature.
    This has been discussed as a potential feature for 5.3, but was
    discussed after no small amount of flames and acrimony. here is the
    relevant wiki page:

    http://wiki.php.net/rfc/shortsyntaxforarrays

    cheers, Jeff
    okey. another syntax:

    myfunc($('key1'=>'val1', 'key2'=>'val2', ...));

    this can be implemented just as a shortcut for the array keyword. i
    think it won't be very hard to extend syntax for the dollar sign.

    my idea is to shorten the syntax. no matter how it will be achieved.

    regards,
    jay
  • Lars Strojny at Dec 18, 2008 at 1:26 am
    Hi Jay,

    Am Donnerstag, den 18.12.2008, 03:18 +0200 schrieb jay:
    [...]
    okey. another syntax:

    myfunc($('key1'=>'val1', 'key2'=>'val2', ...));

    this can be implemented just as a shortcut for the array keyword. i
    think it won't be very hard to extend syntax for the dollar sign.

    my idea is to shorten the syntax. no matter how it will be achieved.
    Obviously you preferred not to read the RFC and you did not read the
    related mailinglist threads. Anyway, to shorten things a bit: it has
    been discussed this year, we decided against it, things are settled.

    Thanks for your attention,
    Lars
    --
    Jabber: lars@strojny.net
    Weblog: http://usrportage.de
  • Jay at Dec 18, 2008 at 1:38 am

    On Thu, 2008-12-18 at 02:26 +0100, Lars Strojny wrote:
    Hi Jay,

    Am Donnerstag, den 18.12.2008, 03:18 +0200 schrieb jay:
    [...]
    okey. another syntax:

    myfunc($('key1'=>'val1', 'key2'=>'val2', ...));

    this can be implemented just as a shortcut for the array keyword. i
    think it won't be very hard to extend syntax for the dollar sign.

    my idea is to shorten the syntax. no matter how it will be achieved.
    Obviously you preferred not to read the RFC and you did not read the
    related mailinglist threads. Anyway, to shorten things a bit: it has
    been discussed this year, we decided against it, things are settled.

    Thanks for your attention,
    Lars
    okey. it's you right to be against such simplification. but anyway it'd
    be nice to have more simple and clear syntax. i hope you'll get back to
    this idea in future. thanks for your replies.

    regards,
    jay
  • Christian Schneider at Dec 18, 2008 at 11:20 am

    jay wrote:
    okey. another syntax:
    myfunc($('key1'=>'val1', 'key2'=>'val2', ...));
    This has been discussed and rejected several times.

    If you still want to be able to use this syntax you can use my patch at
    http://cschneid.com/php/
    including a script to convert from and to this syntax.
    We use this in our production environment so the patch will be updated
    for future PHP versions ;-)

    If you want to use it in an environment where you cannot patch PHP you
    could use our toolkit which provides an auto_prepend file with
    just-in-time translation from new to old syntax.
    See: http://itools.search.ch/

    Regards,
    - Chris
  • Jay I. at Dec 18, 2008 at 11:39 am
    interesting idea, thanks. but unfortunately it won't help me as i really
    need to pass arrays as a single argument like this:

    my_func($param_1,$param_2,array(...));

    i'm unaware of how to make patches for php so i wonder is it possible to
    add a dollar sign shortcut for array keyword. like this:

    my_func($param_1,$param_2,$(1, 2, 3));

    regards,
    jay
    On Thu, 2008-12-18 at 12:20 +0100, Christian Schneider wrote:
    jay wrote:
    okey. another syntax:
    myfunc($('key1'=>'val1', 'key2'=>'val2', ...));
    This has been discussed and rejected several times.

    If you still want to be able to use this syntax you can use my patch at
    http://cschneid.com/php/
    including a script to convert from and to this syntax.
    We use this in our production environment so the patch will be updated
    for future PHP versions ;-)

    If you want to use it in an environment where you cannot patch PHP you
    could use our toolkit which provides an auto_prepend file with
    just-in-time translation from new to old syntax.
    See: http://itools.search.ch/

    Regards,
    - Chris
  • Christian Schneider at Dec 18, 2008 at 11:58 am

    Jay I. wrote:
    interesting idea, thanks. but unfortunately it won't help me as i really
    need to pass arrays as a single argument like this:

    my_func($param_1,$param_2,array(...));
    You can do that. All parameters in a row with => will be merged to one
    array.

    You could call
    myfunc($a, $b, 'foo' => "bar", 'qux' => "quux");
    with our patch

    You can free mix arrays and scalar values like
    myfunc($a, 'b' => "foo", $c, 'd' => "bar", ...);
    which is the same as
    myfunc($a, array('b' => "foo"), $c, array('d' => "foo"), ...);

    And if you need two separate arrays in a row you can still go back to
    having array() for the second one (but we avoid parameter lists like that).

    Ok, enough plugging of that syntax on the list, further replies will be
    off-list ;-)

    - Chris

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedDec 18, '08 at 12:29a
activeDec 18, '08 at 11:58a
posts8
users4
websitephp.net

People

Translate

site design / logo © 2022 Grokbase