pajoye Sat, 23 Jul 2011 20:23:21 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=313641
Log: - add short array syntax as defined in https://wiki.php.net/rfc/shortsyntaxforarrays, 2nd solution using => only Changed paths: U php/php-src/branches/PHP_5_4/UPGRADING U php/php-src/branches/PHP_5_4/Zend/zend_ini_scanner.c U php/php-src/branches/PHP_5_4/Zend/zend_language_parser.y A php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_001.phpt A php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_002.phpt A php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_003.phpt A php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_005.phpt U php/php-src/trunk/UPGRADING U php/php-src/trunk/Zend/zend_language_parser.y A php/php-src/trunk/tests/lang/array_shortcut_001.phpt A php/php-src/trunk/tests/lang/array_shortcut_002.phpt A php/php-src/trunk/tests/lang/array_shortcut_003.phpt A php/php-src/trunk/tests/lang/array_shortcut_005.phpt
Modified: php/php-src/branches/PHP_5_4/UPGRADING =================================================================== --- php/php-src/branches/PHP_5_4/UPGRADING 2011-07-23 19:08:43 UTC (rev 313640) +++ php/php-src/branches/PHP_5_4/UPGRADING 2011-07-23 20:23:21 UTC (rev 313641) @@ -456,5 +456,10 @@ - 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]; - Modified: php/php-src/branches/PHP_5_4/Zend/zend_ini_scanner.c =================================================================== --- php/php-src/branches/PHP_5_4/Zend/zend_ini_scanner.c 2011-07-23 19:08:43 UTC (rev 313640) +++ php/php-src/branches/PHP_5_4/Zend/zend_ini_scanner.c 2011-07-23 20:23:21 UTC (rev 313641) @@ -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" /* +----------------------------------------------------------------------+ Modified: php/php-src/branches/PHP_5_4/Zend/zend_language_parser.y =================================================================== --- php/php-src/branches/PHP_5_4/Zend/zend_language_parser.y 2011-07-23 19:08:43 UTC (rev 313640) +++ php/php-src/branches/PHP_5_4/Zend/zend_language_parser.y 2011-07-23 20:23:21 UTC (rev 313641) @@ -761,6 +761,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; } | '`' 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 { 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; } ; Added: php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_001.phpt =================================================================== --- php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_001.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_001.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 +) Added: php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_002.phpt =================================================================== --- php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_002.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_002.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 +) Added: php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_003.phpt =================================================================== --- php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_003.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_003.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 +) Added: php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_005.phpt =================================================================== --- php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_005.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/tests/lang/array_shortcut_005.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 + ) + +) Modified: php/php-src/trunk/UPGRADING =================================================================== --- php/php-src/trunk/UPGRADING 2011-07-23 19:08:43 UTC (rev 313640) +++ php/php-src/trunk/UPGRADING 2011-07-23 20:23:21 UTC (rev 313641) @@ -448,4 +448,8 @@ - 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]; Modified: php/php-src/trunk/Zend/zend_language_parser.y =================================================================== --- php/php-src/trunk/Zend/zend_language_parser.y 2011-07-23 19:08:43 UTC (rev 313640) +++ php/php-src/trunk/Zend/zend_language_parser.y 2011-07-23 20:23:21 UTC (rev 313641) @@ -761,6 +761,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; } | '`' 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 { 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; } ; Added: php/php-src/trunk/tests/lang/array_shortcut_001.phpt =================================================================== --- php/php-src/trunk/tests/lang/array_shortcut_001.phpt (rev 0) +++ php/php-src/trunk/tests/lang/array_shortcut_001.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 +) Added: php/php-src/trunk/tests/lang/array_shortcut_002.phpt =================================================================== --- php/php-src/trunk/tests/lang/array_shortcut_002.phpt (rev 0) +++ php/php-src/trunk/tests/lang/array_shortcut_002.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 +) Added: php/php-src/trunk/tests/lang/array_shortcut_003.phpt =================================================================== --- php/php-src/trunk/tests/lang/array_shortcut_003.phpt (rev 0) +++ php/php-src/trunk/tests/lang/array_shortcut_003.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 +) Added: php/php-src/trunk/tests/lang/array_shortcut_005.phpt =================================================================== --- php/php-src/trunk/tests/lang/array_shortcut_005.phpt (rev 0) +++ php/php-src/trunk/tests/lang/array_shortcut_005.phpt 2011-07-23 20:23:21 UTC (rev 313641) @@ -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 + ) + +)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php