Some thoughts on the Interface Default Methods RFC

2023/06/27
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The Interface Default Methods RFC proposes a new feature for PHP that would allow interfaces to have default method implementations. The author of the RFC, Anthony Ferrara, argues that this feature would make it easier to evolve interfaces over time without breaking existing code that implements them.

The article shows a video of Ferrara explaining the RFC and its benefits. He gives an example of how this feature could be used to add a new method to an existing interface without breaking any code that implements it. He also addresses some concerns that have been raised about the proposal, such as the potential for abuse and the impact on performance.

For developers who want to keep up with the latest news in PHP, this RFC is worth following. It has been accepted for PHP 8.0, which is expected to be released in late 2020. Developers can start experimenting with this feature now by using the latest PHP 8.0 alpha releases.

Here's an example of how the new feature could be used:

interface MyInterface {
    public function foo();
    public function bar() {
        // Default implementation
    }
}

class MyClass implements MyInterface {
    public function foo() {
        // Implementation
    }
    // bar() is already implemented by default
}

Overall, the Interface Default Methods RFC is a promising addition to PHP that could make it easier to write and maintain code over time.