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
More magic. The difference between these two lines:
$a = array(1,2,3);
$a = [ 1,2,3 ];
is that with the first you can go and look up the array keyword and see
what it does, whereas on the second line you have no idea. You can't look
up a [
You are right that arrays are common and that this might be a case to
break the no-magic PHP rule, but I am personally not in favour of breaking
it for this case.
-Rasmus
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
Christian Schneider wrote:
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 :-)
You're on the right list. If you don't get any more responses, it's just
because something's wrong with your idea. ;-)
Looks cool, though I've never touched ZE2 and, sadly, have no knowledge
of the parser...
Ken
- Chris
[patch]
Hi Christian,
Personally I don't like having two ways of doing things. It makes it harder
for people to read scripts.
However, I think the proposed syntax is significantly more elegant than
today's array() which makes me think twice about the idea and possibly
making an exception to the rule. I think it'll improve the look of PHP
scripts. Also I think people calling methods using call_user_method([$obj,
"method"]); will find it sexier than the array() syntax.
I guess I think it'd be interesting to see what other's think. Also,
another point to check is if list() can also be converted into [] because
having a hybrid wouldn't be too nice.
Andi
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_PRINTexpr { zend_do_print(&$$, &$2 TSRMLS_CC); }
;
Very cool.
How about supporting .. syntax, btw. as in [1..3] or ["a".."z"]? Might
no be the worth, just thinking out loud ;)
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_PRINTexpr { zend_do_print(&$$, &$2 TSRMLS_CC); }
;
Very cool.
How about supporting .. syntax, btw. as in [1..3] or ["a".."z"]? Might
no be the worth, just thinking out loud ;)
"might not be worth it"..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_PRINTexpr { zend_do_print(&$$, &$2 TSRMLS_CC); }
;
Your idea is even cooler...;)
I would like to have these in PHP.
Kouber
"Michael Walter" cm@leetspeak.org wrote in message
news:3FA8BC03.9050104@leetspeak.org...
Very cool.
How about supporting .. syntax, btw. as in [1..3] or ["a".."z"]? Might
no be the worth, just thinking out loud ;)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_PRINTexpr { zend_do_print(&$$, &$2 TSRMLS_CC); }
;
I do not like the new syntax at all. If anything it seems rather unnatural and
what do you save, typing of 5 characters that makes it clear that this is an
array to even the most novice of users? It certainly not going to make the
code any faster and if anything will only add confusion.
Firm -1.
Ilia
On Wed, 5 Nov 2003 08:06:53 -0500
Ilia Alshanetsky ilia@prohost.org wrote:
I do not like the new syntax at all. If anything it seems rather unnatural and > what do you save, typing of 5 characters that makes it clear that this is an
array to even the most novice of users? It certainly not going to make the
code any faster and if anything will only add confusion.Firm -1.
I totally agree with Ilia.
And it doesn't take more than 0.4 seconds to type "array" anyway.
array("My 0.2c, " => "Magnus");
--
What does it mean if there is no fortune for you?
I do not like the new syntax at all. If anything it seems rather unnatural and
what do you save, typing of 5 characters that makes it clear that this is an
array to even the most novice of users? It certainly not going to make the
code any faster and if anything will only add confusion.Firm -1.
Right, one point of confusion is using [] both for initialising array
and indexing them. I'm -1 on this too, array() and range() wosk fine.
Derick
--
"Interpreting what the GPL actually means is a job best left to those
that read the future by examining animal entrails."
Derick Rethans http://derickrethans.nl/
International PHP Magazine http://php-mag.net/
I do not like the new syntax at all. If anything it seems rather unnatural and
what do you save, typing of 5 characters that makes it clear that this is an
array to even the most novice of users? It certainly not going to make the
code any faster and if anything will only add confusion.Firm -1.
There's enough magic already..I could say +1 if magic_quotes_*
is removed and everything is made case-sensitive first. :)
--Jani
OK .. I'm a wobbler.
I think it would be cool to have the cleaner alternative syntax; I think I'd
use it in some situations and not others, and I think that that in itself
would make my code virtually unmaintainable by anyone else.
As Andi originally said, having more than one way to do things isn't always
a good thing.
Add me to the -1 list. Even tho' it's a cool idea.
- Steph
-----Original Message-----
From: Christian Schneider [mailto:cschneid@cschneid.com]
Sent: 04 November 2003 23:33
To: internals@lists.php.net
Subject: [PHP-DEV] Proposal: Array syntaxI 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