- add short array syntax as defined in https://wiki.php.net/rfc/shortsyntaxforarrays, 2nd solution using => only

This commit is contained in:
Pierre Joye 2011-07-23 20:23:21 +00:00
parent 1fc4bc1d56
commit 80496c9dc4
7 changed files with 68 additions and 2 deletions

View File

@ -456,5 +456,10 @@ UPGRADE NOTES - PHP X.Y
- fnv132
- fnv164
- joaat
k. New Syntax
- Short array syntax
$a = [1, 2, 3, 4];
$a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];
$a = ['one' => 1, 2, 'three' => 3, 4];

View File

@ -1,4 +1,4 @@
/* Generated by re2c 0.13.5 on Wed Jun 29 02:53:12 2011 */
/* Generated by re2c 0.13.5 on Mon Jan 17 14:03:33 2011 */
#line 1 "Zend/zend_ini_scanner.l"
/*
+----------------------------------------------------------------------+

View File

@ -761,6 +761,7 @@ expr_without_variable:
| '@' { 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; }
| '`' backticks_expr '`' { zend_do_shell_exec(&$$, &$2 TSRMLS_CC); }
| T_PRINT expr { zend_do_print(&$$, &$2 TSRMLS_CC); }
| function is_reference '(' { zend_do_begin_lambda_function_declaration(&$$, &$1, $2.op_type, 0 TSRMLS_CC); }
@ -894,6 +895,7 @@ static_scalar: /* compile-time evaluated scalars */
| '+' static_scalar { ZVAL_LONG(&$1.u.constant, 0); add_function(&$2.u.constant, &$1.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
| '-' static_scalar { ZVAL_LONG(&$1.u.constant, 0); sub_function(&$2.u.constant, &$1.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
| T_ARRAY '(' static_array_pair_list ')' { $$ = $3; Z_TYPE($$.u.constant) = IS_CONSTANT_ARRAY; }
| '[' static_array_pair_list ']' { $$ = $2; Z_TYPE($$.u.constant) = IS_CONSTANT_ARRAY; }
| static_class_constant { $$ = $1; }
;

View File

@ -0,0 +1,13 @@
--TEST--
Square bracket array shortcut test
--FILE--
<?php
print_r([1, 2, 3]);
?>
--EXPECT--
Array
(
[0] => 1
[1] => 2
[2] => 3
)

View File

@ -0,0 +1,13 @@
--TEST--
Square bracket associative array shortcut test
--FILE--
<?php
print_r(["foo" => "orange", "bar" => "apple", "baz" => "lemon"]);
?>
--EXPECT--
Array
(
[foo] => orange
[bar] => apple
[baz] => lemon
)

View File

@ -0,0 +1,13 @@
--TEST--
Testing array shortcut and bracket operator
--FILE--
<?php
$a = [1, 2, 3, 4, 5];
print_r([$a[1], $a[3]]);
?>
--EXPECT--
Array
(
[0] => 2
[1] => 4
)

View File

@ -0,0 +1,20 @@
--TEST--
Testing nested array shortcut
--FILE--
<?php
print_r([1, 2, 3, ["foo" => "orange", "bar" => "apple", "baz" => "lemon"]]);
?>
--EXPECT--
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => Array
(
[foo] => orange
[bar] => apple
[baz] => lemon
)
)