summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xUPGRADING7
-rw-r--r--Zend/zend_ini_scanner.c2
-rw-r--r--Zend/zend_language_parser.y2
-rw-r--r--tests/lang/array_shortcut_001.phpt13
-rw-r--r--tests/lang/array_shortcut_002.phpt13
-rw-r--r--tests/lang/array_shortcut_003.phpt13
-rw-r--r--tests/lang/array_shortcut_005.phpt20
7 files changed, 68 insertions, 2 deletions
diff --git a/UPGRADING b/UPGRADING
index 4d9d591cff..dede4da515 100755
--- a/UPGRADING
+++ b/UPGRADING
@@ -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];
diff --git a/Zend/zend_ini_scanner.c b/Zend/zend_ini_scanner.c
index 0e09603358..8b1802f3d7 100644
--- a/Zend/zend_ini_scanner.c
+++ b/Zend/zend_ini_scanner.c
@@ -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"
/*
+----------------------------------------------------------------------+
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 089209154a..140d742d04 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -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; }
;
diff --git a/tests/lang/array_shortcut_001.phpt b/tests/lang/array_shortcut_001.phpt
new file mode 100644
index 0000000000..18a10ea09b
--- /dev/null
+++ b/tests/lang/array_shortcut_001.phpt
@@ -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
+)
diff --git a/tests/lang/array_shortcut_002.phpt b/tests/lang/array_shortcut_002.phpt
new file mode 100644
index 0000000000..25aee9ba39
--- /dev/null
+++ b/tests/lang/array_shortcut_002.phpt
@@ -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
+)
diff --git a/tests/lang/array_shortcut_003.phpt b/tests/lang/array_shortcut_003.phpt
new file mode 100644
index 0000000000..75e428b63e
--- /dev/null
+++ b/tests/lang/array_shortcut_003.phpt
@@ -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
+)
diff --git a/tests/lang/array_shortcut_005.phpt b/tests/lang/array_shortcut_005.phpt
new file mode 100644
index 0000000000..7cc7386f83
--- /dev/null
+++ b/tests/lang/array_shortcut_005.phpt
@@ -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
+ )
+
+)