rfc:short-functions

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
Last revisionBoth sides next revision
rfc:short-functions [2021/04/25 18:55] – Header formatting tweaks crellrfc:short-functions [2021/06/15 18:36] – Close vote. crell
Line 3: Line 3:
   * Date: 2020-10-20   * Date: 2020-10-20
   * Author: Larry Garfield (larry@garfieldtech.com)   * Author: Larry Garfield (larry@garfieldtech.com)
-  * Status: In Discussion+  * Status: Not passed
   *  First Published at: http://wiki.php.net/rfc/short-functions   *  First Published at: http://wiki.php.net/rfc/short-functions
  
Line 51: Line 51:
  
 This RFC is designed to complement the [[rfc:auto-capture-closure|Auto-capturing multi-statement closures]] RFC.  Both stand on their own and offer independent benefits.  However, they have been designed such that their syntax is complementary and consistent.  Specifically: This RFC is designed to complement the [[rfc:auto-capture-closure|Auto-capturing multi-statement closures]] RFC.  Both stand on their own and offer independent benefits.  However, they have been designed such that their syntax is complementary and consistent.  Specifically:
- 
  
   * The ''=>'' sigil always means "evaluates to the expression on the right," in all circumstances.  (Named functions, anonymous functions, arrays, and ''match()''.)   * The ''=>'' sigil always means "evaluates to the expression on the right," in all circumstances.  (Named functions, anonymous functions, arrays, and ''match()''.)
Line 68: Line 67:
  
 Expressions are becoming increasingly capable, too.  match() expressions and throw expressions in PHP 8.0, plus proposals such as [[rfc:pipe-operator-v2|PHP RFC: Pipe Operator v2]], are collectively making it easier to write expressive expressions.  Enumeration methods are likely to consist primarily of a single match() statement.  This improvement is a part of that larger trend. Expressions are becoming increasingly capable, too.  match() expressions and throw expressions in PHP 8.0, plus proposals such as [[rfc:pipe-operator-v2|PHP RFC: Pipe Operator v2]], are collectively making it easier to write expressive expressions.  Enumeration methods are likely to consist primarily of a single match() statement.  This improvement is a part of that larger trend.
 +
 +The trend in PHP in recent years has been toward more compact but still readable syntax that eliminates redundancy.  Property promotion, arrow functions, the nullsafe operator, and similar recent well-received additions demonstrate this trend.  This RFC seeks to continue that trend to make PHP more pleasant to write while still being just as clear to read.
  
 ==== Pure functions ==== ==== Pure functions ====
Line 149: Line 150:
 ==== Getter methods ==== ==== Getter methods ====
  
-Many classes consist primarily or almost entirely out of methods that either return a property, or some computation off of a property.  With short-functions, that becomes considerably more concise.+Many classes consist primarily or almost entirely of methods that either return a property, or some computation off of a property.  With short-functions, that becomes considerably more concise.
  
 <code php> <code php>
Line 439: Line 440:
 </code> </code>
  
-Which is a really nice way to build up a pipeline through composition.  (Modulo PHP's clumsy way of referencing functions by name, which is a separate matter being addressed elsewhere.)+Which is a really nice way to build up a pipeline through composition.  Modulo PHP's clumsy way of referencing functions by name, which is a separate matter that would be addressed by the [[rfc:partial_function_application|Partial Function Application]] RFC The three RFCs together would allow for this: 
 + 
 +<code php> 
 +function doAThing(User $u) => $u 
 +    |> step1(?)  
 +    |> step2(?) 
 +    |> step3($val, ?)  
 +    |> step4(?, $var) 
 +
 +</code> 
  
 ==== clone-with ==== ==== clone-with ====
Line 476: Line 487:
 This is a simple up-or-down vote, requiring 2/3 approval to pass. This is a simple up-or-down vote, requiring 2/3 approval to pass.
  
-===== Patches and Tests =====+Voting started 2021-05-31 and closes 2021-06-14.
  
-[[https://github.com/php/php-src/pull/6221|Pull request with the code.]]+<doodle title="Include short-function syntax in PHP" auth="crell" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
-===== Implementation ===== +===== Patches and Tests =====
-After the project is implemented, this section should contain  +
-  - the version(s) it was merged into +
-  - a link to the git commit(s) +
-  - a link to the PHP manual entry for the feature +
-  - a link to the language specification section (if any)+
  
-===== References ===== +[[https://github.com/php/php-src/pull/6221|Pull request with the code.]]
-Links to external references, discussions or RFCs+
  
-===== Rejected Features ===== 
-Keep this updated with features that were discussed on the mail lists. 
rfc/short-functions.txt · Last modified: 2021/06/15 22:29 by ilutov