Re[2]: [PHP-DEV] Proposal: Array syntax

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re[2]: [PHP-DEV] Proposal: Array syntax

    Hi

    The problem i see when using array() (or list()) is that it nearly looks
    like it is a function, but it isn't. Using [] instead would clearly
    mark this difference.
    array() and list() are special language constructs, why shouldn't they look a bit special?
    This doesn't break backwards compatibility and it makes new code look
    better and more readable.

    Daniel Penning

    Am Mittwoch, 5. November 2003 um 09:49 schrieben Sie:

    AG> Hi Christian,

    AG> Personally I don't like having two ways of doing things. It makes it harder
    AG> for people to read scripts.
    AG> However, I think the proposed syntax is significantly more elegant than
    AG> today's array() which makes me think twice about the idea and possibly
    AG> making an exception to the rule. I think it'll improve the look of PHP
    AG> scripts. Also I think people calling methods using call_user_method([$obj,
    AG> "method"]); will find it sexier than the array() syntax.
    AG> I guess I think it'd be interesting to see what other's think. Also,
    AG> another point to check is if list() can also be converted into [] because
    AG> having a hybrid wouldn't be too nice.

    AG> Andi

    AG> At 12:33 AM 11/5/2003 +0100, Christian Schneider wrote:
    >>I propose to add an alternative (backward compatible) short array creation
    >>syntax:
    >>$a = [ 1, 2, 3 ]; and $a = [ 'a' => 42, 'b' => "foo" ];
    >>
    >>It can also be used in function calls:
    >>img(['src' => "logo.gif", 'alt' => "Logo"]);
    >>
    >>Reason behind this change: Arrays are used a lot and should therefore have
    >>as little syntactic overhead as possible. And I think the short syntax is
    >>also easier to read and write.
    >>
    >>A patch for the parser is trivial and is attached for Zend2.
    >>
    >>Note: I checked the newsgroup archive but couldn't find a discussion about
    >>this. After not hearing back about my proposed enhancement to
    >>debug_backtrace() and the dangling comma for function call parameters
    >>being rejected I wonder if I'm using the right mailing list for this :-)
    >>
    >>- Chris
    >>
    >>
    >>Index: Zend/zend_language_parser.y
    >>================================================ ===================
    >>RCS file: /repository/ZendEngine2/zend_language_parser.y,v
    >>retrieving revision 1.127
    >>diff -u -r1.127 zend_language_parser.y
    >>--- Zend/zend_language_parser.y 19 Oct 2003 08:38:48 -0000 1.127
    >>+++ Zend/zend_language_parser.y 4 Nov 2003 23:32:12 -0000
    >>@@ -581,6 +581,7 @@
    >> | '@' { zend_do_begin_silence(&$1 TSRMLS_CC); } expr {
    >> zend_do_end_silence(&$1 TSRMLS_CC); $$ = $3; }
    >> | scalar { $$ = $1; }
    >> | T_ARRAY '(' array_pair_list ')' { $$ = $3; }
    >>+ | '[' array_pair_list ']' { $$ = $2; }
    >> | '`' encaps_list '`' { zend_do_shell_exec(&$$,
    >> &$2 TSRMLS_CC); }
    >> | T_PRINT expr { zend_do_print(&$$, &$2 TSRMLS_CC); }
    >> ;
    >>
    >>--
    >>PHP Internals - PHP Runtime Development Mailing List
    >>To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    s0niX Guest

  2. Similar Questions and Discussions

    1. [PHP-DEV] Proposal: Array syntax
      --------------000102040006030200070405 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit I propose to...
    2. [PHP-DEV] EOT (was [PHP-DEV] Proposal: Array syntax)
      On Thu, 6 Nov 2003, Andi Gutmans wrote: If there was anything constructive in that long thread of "I like it" -- "no, I don't!" I might agree...
    3. [PHP-DEV] EOT (was [PHP-DEV] Proposal: Array syntax)
      Sascha, I don't think it's a private matter. Feel free to delete the emails with this subject when they come in. Andi At 01:30 PM 11/6/2003...
    4. [PHP-DEV] EOT (was [PHP-DEV] Proposal: Array syntax)
      Please move this thread to private email. - Sascha -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:...
    5. Proposal: Array#to_h, to simplify hash generation
      Hi -talk, Ruby has wonderful support for chewing and spitting arrays. For instance, it's easy to produce an array from any Enumerable using...
  3. #2

    Default RE: Re[2]: [PHP-DEV] Proposal: Array syntax

    s0niX wrote:
    > The problem i see when using array() (or list()) is that it nearly looks
    > like it is a function, but it isn't. Using [] instead would clearly
    > mark this difference.
    > array() and list() are special language constructs, why shouldn't
    > they look a bit special?
    > This doesn't break backwards compatibility and it makes new code look
    > better and more readable.
    >
    Indeed. It's a nice idea.
    Having that syntax as an alternative to list() would be cool too.

    Whether it has enough steam to get around the magic rule I'll
    leave to others, because the rule is there for a reason. :)

    Best Regards
    Mike Robinson

    >
    > Am Mittwoch, 5. November 2003 um 09:49 schrieben Sie:
    >
    > AG> Hi Christian,
    >
    > AG> Personally I don't like having two ways of doing things. It
    > makes it harder
    > AG> for people to read scripts.
    > AG> However, I think the proposed syntax is significantly more
    > elegant than
    > AG> today's array() which makes me think twice about the idea and
    > possibly
    > AG> making an exception to the rule. I think it'll improve the
    > look of PHP
    > AG> scripts. Also I think people calling methods using
    > call_user_method([$obj,
    > AG> "method"]); will find it sexier than the array() syntax.
    > AG> I guess I think it'd be interesting to see what other's think. Also,
    > AG> another point to check is if list() can also be converted
    > into [] because
    > AG> having a hybrid wouldn't be too nice.
    >
    > AG> Andi
    >
    > AG> At 12:33 AM 11/5/2003 +0100, Christian Schneider wrote:
    > >>I propose to add an alternative (backward compatible) short
    > array creation
    > >>syntax:
    > >>$a = [ 1, 2, 3 ]; and $a = [ 'a' => 42, 'b' => "foo" ];
    > >>
    > >>It can also be used in function calls:
    > >>img(['src' => "logo.gif", 'alt' => "Logo"]);
    > >>
    > >>Reason behind this change: Arrays are used a lot and should
    > therefore have
    > >>as little syntactic overhead as possible. And I think the short
    > syntax is
    > >>also easier to read and write.
    > >>
    > >>A patch for the parser is trivial and is attached for Zend2.
    > >>
    > >>Note: I checked the newsgroup archive but couldn't find a
    > discussion about
    > >>this. After not hearing back about my proposed enhancement to
    > >>debug_backtrace() and the dangling comma for function call parameters
    > >>being rejected I wonder if I'm using the right mailing list for this :-)
    > >>
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Mike Robinson Guest

  4. #3

    Default Re: Re[2]: [PHP-DEV] Proposal: Array syntax

    I like it a lot as well. Having the [] syntax also support range()-like
    calls would be a very nice idea as well. :D

    Regards,

    Manuzhai

    "Mike Robinson" <mike@fiddy8.com> wrote in message
    news:PPEJIJHNCLOJJONNJNMJCEKPCAAA.mike@fiddy8.com. ..
    > s0niX wrote:
    >
    > > The problem i see when using array() (or list()) is that it nearly looks
    > > like it is a function, but it isn't. Using [] instead would clearly
    > > mark this difference.
    > > array() and list() are special language constructs, why shouldn't
    > > they look a bit special?
    > > This doesn't break backwards compatibility and it makes new code look
    > > better and more readable.
    > >
    >
    > Indeed. It's a nice idea.
    > Having that syntax as an alternative to list() would be cool too.
    >
    > Whether it has enough steam to get around the magic rule I'll
    > leave to others, because the rule is there for a reason. :)
    >
    > Best Regards
    > Mike Robinson
    >
    >
    > >
    > > Am Mittwoch, 5. November 2003 um 09:49 schrieben Sie:
    > >
    > > AG> Hi Christian,
    > >
    > > AG> Personally I don't like having two ways of doing things. It
    > > makes it harder
    > > AG> for people to read scripts.
    > > AG> However, I think the proposed syntax is significantly more
    > > elegant than
    > > AG> today's array() which makes me think twice about the idea and
    > > possibly
    > > AG> making an exception to the rule. I think it'll improve the
    > > look of PHP
    > > AG> scripts. Also I think people calling methods using
    > > call_user_method([$obj,
    > > AG> "method"]); will find it sexier than the array() syntax.
    > > AG> I guess I think it'd be interesting to see what other's think. Also,
    > > AG> another point to check is if list() can also be converted
    > > into [] because
    > > AG> having a hybrid wouldn't be too nice.
    > >
    > > AG> Andi
    > >
    > > AG> At 12:33 AM 11/5/2003 +0100, Christian Schneider wrote:
    > > >>I propose to add an alternative (backward compatible) short
    > > array creation
    > > >>syntax:
    > > >>$a = [ 1, 2, 3 ]; and $a = [ 'a' => 42, 'b' => "foo" ];
    > > >>
    > > >>It can also be used in function calls:
    > > >>img(['src' => "logo.gif", 'alt' => "Logo"]);
    > > >>
    > > >>Reason behind this change: Arrays are used a lot and should
    > > therefore have
    > > >>as little syntactic overhead as possible. And I think the short
    > > syntax is
    > > >>also easier to read and write.
    > > >>
    > > >>A patch for the parser is trivial and is attached for Zend2.
    > > >>
    > > >>Note: I checked the newsgroup archive but couldn't find a
    > > discussion about
    > > >>this. After not hearing back about my proposed enhancement to
    > > >>debug_backtrace() and the dangling comma for function call parameters
    > > >>being rejected I wonder if I'm using the right mailing list for this
    :-)
    > > >>
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Dirkjan Ochtman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139