rfc:default_expression

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
rfc:default_expression [2024/08/29 08:50] bilgerfc:default_expression [2024/08/29 21:46] (current) – Added two seconary discussion concerns bilge
Line 141: Line 141:
 ===== Discussion ===== ===== Discussion =====
  
-The greatest concern is the proposed grammar is too permissive and has drawbacks. A secondary concern is default values are now part of an object's public API. We will examine each of these issues in detail.+The greatest concern is the proposed grammar is too permissive and has drawbacks. Secondary concerns include evaluating <php>default</php> in the calling context, and default values are now part of an object's public API. We will examine each of these issues in detail.
  
 ==== Limiting grammar ==== ==== Limiting grammar ====
Line 176: Line 176:
 test(new D); // Fatal error: Uncaught TypeError: Unsupported operand types: string + int. test(new D); // Fatal error: Uncaught TypeError: Unsupported operand types: string + int.
 </code> </code>
 +
 +==== Default as a dummy value ====
 +
 +Currently <php>default</php>, as described by this RFC, is effectively replaced by the callee's default value and then passed to the callee from the caller, meaning the caller has full access to the default value. Some have [[https://externals.io/message/125183#125265|argued]] for an implementation that more literally follows the premise of this RFC, which is that <php>default</php> is just a dumb token that is standing in for //nothing//; it does not represent any value to the caller and merely instructs the callee to use its default value in the same way as when not passing the argument.
  
 ==== Defaults as a contract ==== ==== Defaults as a contract ====
 +
 +Some have argued allowing <php>default</php> to read argument default values, previously only accessible via reflection, suddenly makes defaults part of an object's published API. However, changing a default is a behavioural change for any caller previously relying on those defaults (by not passing any argument), ergo defaults have always been part of the published API.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 299: Line 305:
 // Match // Match
 F(match(default) { default => default }) F(match(default) { default => default })
 +
 +// Callable
 +F((default)->M())
  
 // Parens // Parens
rfc/default_expression.1724921425.txt.gz · Last modified: 2024/08/29 08:50 by bilge