Skip to content

Automatic Method Signature Inheritance for Abstract Classes in PHP #18837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mohammadMghi opened this issue Jun 11, 2025 · 2 comments
Open

Comments

@mohammadMghi
Copy link

Description

I’ve noticed something in PHP that could really improve the language if added as a feature.

Imagine this scenario:
You have an abstract class with a method called funcA(param1), and there are 40 subclasses that implement this method.

Now, suppose you want to add a second parameter, so funcA becomes funcA(param1, param2). Updating all 40 subclasses manually becomes tedious and error-prone.

It would be incredibly helpful if you could just update the method signature in the abstract class, and have all subclasses inherit the change automatically — without needing to modify each one individually.

This would make code much more maintainable and extensible.

@iluuu1994
Copy link
Member

Hi @mohammadMghi. Treating missing parameters as compatible also means child implementations that call the parent will silently break by not handling the new parameter, because parent::funcA($param1); needs to be updated to parent::funcA($param1, $param2);. I highly suspect this is not a tradeoff internals are willing to accept, but feel free to try your lock on the internals mailing list.

@ddevsr
Copy link

ddevsr commented Jun 12, 2025

In community, PHP already have tooling detection like PHPStan and automatic refactoring using Rector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants