rfc:bare_name_array_literal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:bare_name_array_literal [2014/06/20 19:30] – impact ajfrfc: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 <ajf@ajf.me>   * Author: Andrea Faulds <ajf@ajf.me>
-  * Status: Under Discussion+  * Status: Declined
   * First Published at: http://wiki.php.net/rfc/bare_name_array_literal   * First Published at: http://wiki.php.net/rfc/bare_name_array_literal
  
Line 71: Line 71:
 Symmetry between arrays and named parameters would be desirable as otherwise it could cause confusion. This RFC would ensure it. Symmetry between arrays and named parameters would be desirable as otherwise it could cause confusion. This RFC would ensure it.
  
-This also complements the [[rfc:bare_name_array_dereference|Bare Name Array Dereference]] RFC, as both this proposal and that one deal with using bare T_STRING names for array keys.+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: [method: "GET", header: "Accept-language: en", user_agent: 'Foo-Bot', protocol_version: 1.1]]); 
 + 
 +// or 
 + 
 +$hash = password_hash($_POST['pwd'], PASSWORD_BCRYPT, [salt: $secure_salt, cost: 25]); 
 +</code> 
 + 
 +This makes creating JSON more convenient, too: 
 + 
 +<code php> 
 +// Real example 
 +$ws->send(json_encode([ 
 +    type: 'join', 
 +    room: $player->currentRoom, 
 +    nick: $player->curretName, 
 +    x: 0, 
 +    y: 0, 
 +    avatar: 'foo.png' 
 +])); 
 +</code> 
 + 
 +This complements the [[rfc:bare_name_array_dereference|Bare Name Array Dereference]] RFC, as both this proposal and that one deal with using bare T_STRING names for array keys.
  
 ===== Proposal ===== ===== Proposal =====
Line 95: Line 119:
  
 <code php> <code php>
-const('foo', 'bar');+const foo 'bar';
 $arr = [foo: 3]; $arr = [foo: 3];
 // array(1) { // array(1) {
Line 140: 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) and ended 2014-06-28.  
-<doodle title="Merge into master/PHP 5.7?" auth=ajf" voteType="single" closed="false">+<doodle title="Merge bare name array literal into master/PHP 5.7?" auth="user" voteType="single" closed="true">
    * Yes    * Yes
    * No    * No
rfc/bare_name_array_literal.1403292611.txt.gz · Last modified: 2017/09/22 13:28 (external edit)