rfc:match_expression_v2

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:match_expression_v2 [2020/05/21 13:59] – Improve examples ilijatovilorfc:match_expression_v2 [2020/07/09 22:06] (current) – Move to implemented ilutov
Line 1: Line 1:
 ====== PHP RFC: Match expression v2 ====== ====== PHP RFC: Match expression v2 ======
  
-  * Date: 2020-05-16+  * Date: 2020-05-22
   * Author: Ilija Tovilo, tovilo.ilija@gmail.com   * Author: Ilija Tovilo, tovilo.ilija@gmail.com
-  * Status: Under discussion+  * Status: Implemented
   * Target Version: PHP 8.0   * Target Version: PHP 8.0
   * Implementation: https://github.com/php/php-src/pull/5371   * Implementation: https://github.com/php/php-src/pull/5371
Line 121: Line 121:
 }; };
 </code> </code>
-Multiple conditions can be comma-separated to execute the same block of code. There’s no way to achieve the same result as 3 and 4.+Multiple conditions can be comma-separated to execute the same block of code.
  
 <code php> <code php>
Line 142: Line 142:
 // Forgot to handle BinaryOperator::SUBTRACT // Forgot to handle BinaryOperator::SUBTRACT
 </code> </code>
-This will go unnoticed until the program crashes in a weird way, causes strange behavior or even worse becomes a security hole. Many languages can check if all the cases are handled at compile time or force you to write a ''%%default%%'' case if they can’t. For a dynamic language like PHP the only alternative is throwing an error at runtime. This is exactly what the ''%%match%%'' expression does. It throws an ''%%UnhandledMatchError%%'' if the condition isn’t met for any of the arms.+This will go unnoticed until the program crashes in a weird way, causes strange behavior or even worse becomes a security hole. ''%%match%%'' throws an ''%%UnhandledMatchError%%'' if the condition isn’t met for any of the arms. This allows mistakes to be caught early on.
  
 <code php> <code php>
Line 149: Line 149:
 }; };
  
-// Throws when $operator is BinaryOperator::SUBTRACT so we catch the mistake early on+// Throws when $operator is BinaryOperator::SUBTRACT
 </code> </code>
 ===== Miscellaneous ===== ===== Miscellaneous =====
Line 192: Line 192:
  
 Note that it will continue to work in method names and class constants. Note that it will continue to work in method names and class constants.
 +
 +===== Syntax comparison =====
 +https://gist.github.com/iluuu1994/11ac292cf7daca8162798d08db219cd5
  
 ===== Vote ===== ===== Vote =====
  
-Voting started 2020-xx-xx and closes 2020-xx-xx.+Voting starts 2020-06-19 and ends 2020-07-03
  
 +As this is a language change, a 2/3 majority is required.
  
 +<doodle title="Add match expressions to the language?" auth="ilutov" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
rfc/match_expression_v2.1590069546.txt.gz · Last modified: 2020/05/21 13:59 by ilijatovilo