Hi all, I've been following the discussion on the Default Expression RFC, and while I appreciate the effort to introduce more flexibility in handling default values, I have some significant concerns about this proposal. I'd like to share my thoughts and invite further discussion.
1. Complexity vs. Benefit: The proposed `default` expression adds considerable complexity to PHP's syntax. While it might solve some edge cases, I'm not convinced the benefits outweigh the added complexity. Our current methods (named arguments, null coalescing, etc.) already handle most scenarios effectively. 2. Principle of Least Astonishment: PHP developers are used to default values being implicitly used when arguments are omitted. Introducing an explicit `default` keyword changes this expectation and could lead to confusion, especially for newcomers to the language. 3. Type Safety and LSP: The ability to modify default values at the call site raises concerns about type safety. The RFC's example of potential LSP violations is particularly worrying. This could lead to subtle bugs that are hard to track down. 4. Code Readability: One of PHP's strengths is its readability. I'm concerned that `default` expressions, especially when combined with other operations, could make code harder to understand at a glance. 5. Performance Considerations: The RFC mentions using reflection-like mechanisms for `default`. Have we considered the performance implications, especially for high-traffic applications? 6. Inconsistent Behavior: The proposal suggests different behaviors for `default` in various contexts (e.g., function arguments vs. variadic args vs match expressions). This inconsistency could be a source of bugs and confusion. 7. Maintenance Burden: Implementing and maintaining this feature, with all its proposed restrictions and edge cases, seems like it would add a significant burden to the language maintainers. 8. Backward Compatibility: While the RFC claims no known BC breaks, changing the meaning of `default` in certain contexts could potentially cause subtle issues in existing codebases. I understand the motivation behind this RFC, but I'm concerned that it's solving a problem we don't really have, while introducing new ones. Perhaps we could explore alternative ways to address the specific use cases that motivated this proposal? For example, the `applyTheme` function in the proposal can be simply implemented as: ```php function applyTheme(?string $theme = null) { return new Config(...(isset($theme) ? [new $theme] : [])); } ``` This achieves the same result without having to call `array_filter` or rely on reflection, and without introducing a new language construct. What do others think? Am I overlooking some key benefits that would justify these concerns? Looking forward to hearing your thoughts, Cheers, Hammed