rfc:bare_name_array_literal
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:bare_name_array_literal [2014/06/19 23:43] – Fixed vote title ajf | rfc:bare_name_array_literal [2015/12/19 01:27] – fix error in code sample ajf | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2014-06-01 | * Date: 2014-06-01 | ||
* Author: Andrea Faulds < | * Author: Andrea Faulds < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 57: | Line 57: | ||
This means that only 2 characters need to be typed (3 with spaces) for most key names. It makes defining arrays with string keys more convenient and it's easier to read (especially if you have an IDE which syntax highlights strings). | This means that only 2 characters need to be typed (3 with spaces) for most key names. It makes defining arrays with string keys more convenient and it's easier to read (especially if you have an IDE which syntax highlights strings). | ||
+ | |||
+ | A secondary benefit is to the [[rfc: | ||
+ | |||
+ | <code php> | ||
+ | $array = [true, 3, foo: ' | ||
+ | call_user_func_array(' | ||
+ | // is the same as: | ||
+ | quxbang(...$array): | ||
+ | // is the same as: | ||
+ | quxbang(true, | ||
+ | </ | ||
+ | |||
+ | Symmetry between arrays and named parameters would be desirable as otherwise it could cause confusion. This RFC would ensure it. | ||
+ | |||
+ | Even without named parameters, this makes it nicer to use functions which take an array of options. For example: | ||
+ | |||
+ | <code php> | ||
+ | $ctx = stream_context_create([http: | ||
+ | |||
+ | // or | ||
+ | |||
+ | $hash = password_hash($_POST[' | ||
+ | </ | ||
+ | |||
+ | This makes creating JSON more convenient, too: | ||
+ | |||
+ | <code php> | ||
+ | // Real example | ||
+ | $ws-> | ||
+ | type: ' | ||
+ | room: $player-> | ||
+ | nick: $player-> | ||
+ | x: 0, | ||
+ | y: 0, | ||
+ | avatar: ' | ||
+ | ])); | ||
+ | </ | ||
This complements the [[rfc: | This complements the [[rfc: | ||
Line 82: | Line 119: | ||
<code php> | <code php> | ||
- | const('foo', | + | const foo = ' |
$arr = [foo: 3]; | $arr = [foo: 3]; | ||
// array(1) { | // array(1) { | ||
Line 101: | Line 138: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | None. This will not affect existing code. | + | None. This will not affect existing code. => will continue to resolve constants. : will not. |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 110: | Line 147: | ||
SAPIs, extensions, opcache, constants and php.ini are unaffected. No new opcodes are added, this is purely a parsing change. | SAPIs, extensions, opcache, constants and php.ini are unaffected. No new opcodes are added, this is purely a parsing change. | ||
+ | |||
+ | As aforementioned, | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
Line 125: | Line 164: | ||
===== Vote ===== | ===== Vote ===== | ||
- | A 2/3 majority as it is a language change. Voting began on 2014-06-20 and ends 2014-06-27. | + | A 2/3 majority as it is a language change. Voting began on 2014-06-21 (after a hiccup it was restarted) |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
Line 146: | Line 185: | ||
===== References ===== | ===== References ===== | ||
+ | * The [[rfc: | ||
* http:// | * http:// | ||
* The [[rfc: | * The [[rfc: |
rfc/bare_name_array_literal.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1