rfc:conditional_break_continue_return

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:conditional_break_continue_return [2020/05/16 19:20] ralphschindlerrfc:conditional_break_continue_return [2022/04/17 18:38] (current) – Move to inactive ilutov
Line 1: Line 1:
-====== PHP RFC: Conditional Break, Continue, and Return Statements ======+====== PHP RFC: Conditional Return, Break, and Continue Statements ======
   * Version: 1.0   * Version: 1.0
   * Date: 2020-05-16   * Date: 2020-05-16
   * Author: Ralph Schindler, ralphschindler@php.net   * Author: Ralph Schindler, ralphschindler@php.net
-  * Status: Draft+  * Status: Inactive
   * First Published at: http://wiki.php.net/rfc/conditional_break_continue_return   * First Published at: http://wiki.php.net/rfc/conditional_break_continue_return
 ===== Introduction ===== ===== Introduction =====
 +
 +Most generally, this is a syntactical change that (IMO, of course) allows for a terser and more expressive way to achieve conditional returns (along with breaks and continues).
  
 This proposal is a syntatical addition that allows `break`, `continue` and `return` to be conditionally qualified. Two variations are possible (depending on which, if either are desirable to have.) This proposal is a syntatical addition that allows `break`, `continue` and `return` to be conditionally qualified. Two variations are possible (depending on which, if either are desirable to have.)
Line 48: Line 50:
  
 It is also worth mentioning that Ruby has similar features (called a modifier), and I believe they are heavily utilized.. [[https://github.com/rubocop-hq/ruby-style-guide#no-nested-conditionals|see here]]. It is also worth mentioning that Ruby has similar features (called a modifier), and I believe they are heavily utilized.. [[https://github.com/rubocop-hq/ruby-style-guide#no-nested-conditionals|see here]].
 +
 +(While the text of this applies most arguments to `return`, at current the same arguments apply for break and continue, and are included in this proposal.)
  
 ==== Variation #1 ==== ==== Variation #1 ====
Line 80: Line 84:
 Con: Con:
   - Large optional return values will create more space between the `return` and `if` keywords, potentially making it harder for (humans) to scan for the conditional qualifier.   - Large optional return values will create more space between the `return` and `if` keywords, potentially making it harder for (humans) to scan for the conditional qualifier.
 +
 +==== A visual argument between the two variations ====
 +
 +(Click to view full)
 +
 +{{:rfc:return-if-visual-reasoning.png}}
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-No BC issues.+No BC issues: there are no new keywords, nor does not impact any existing code. 
 + 
 +This syntactical change is reusing existing keywords.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 109: Line 121:
  
 The recently contributed [[rfc:guard_statement|Guard RFC]] The recently contributed [[rfc:guard_statement|Guard RFC]]
 +
 +https://stackoverflow.com/questions/5436034/is-there-a-ruby-one-line-return-if-x
 +
 +https://engineering.helpscout.com/reducing-complexity-with-guard-clauses-in-php-and-javascript-74600fd865c7
 +
 +https://guidelines.spatie.be/code-style/laravel-php#avoid-else
 +
  
rfc/conditional_break_continue_return.1589656850.txt.gz · Last modified: 2020/05/16 19:20 by ralphschindler