rfc:bare_name_array_literal
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:bare_name_array_literal [2014/06/01 22:11] – created from bare_name_arrays (split) ajf | rfc:bare_name_array_literal [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
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 58: | Line 58: | ||
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: | ||
===== Proposal ===== | ===== Proposal ===== | ||
Line 71: | Line 109: | ||
<code php> | <code php> | ||
const(' | const(' | ||
- | $arr = [ foo => 3]; | + | $arr = [foo => 3]; |
+ | // array(1) { | ||
+ | // | ||
+ | // | ||
+ | // } | ||
</ | </ | ||
- | By contrast, constants do **not** affect the colon syntax, and the following code would result in an array mapping //' | + | By contrast, constants do **not** affect the colon syntax, and the following code would result in an array mapping |
<code php> | <code php> | ||
- | const('foo', | + | const foo = ' |
- | $arr = [ foo: 3]; | + | $arr = [foo: 3]; |
+ | // array(1) { | ||
+ | // | ||
+ | // | ||
+ | // } | ||
</ | </ | ||
Line 92: | 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 101: | 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 114: | Line 162: | ||
Object literals might be a nice-to-have, | Object literals might be a nice-to-have, | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | A 2/3 majority as it is a language change. | + | A 2/3 majority as it is a language change. |
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 133: | Line 185: | ||
===== References ===== | ===== References ===== | ||
- | * http:// | + | * The [[rfc: |
+ | | ||
+ | * The [[rfc: | ||
+ | * http:// | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
None as yet. | None as yet. |
rfc/bare_name_array_literal.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1