-
Notifications
You must be signed in to change notification settings - Fork 150
[TASK] Drop redundant constructor code #932
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
Conversation
oliverklee
commented
Feb 15, 2025
- use default values for properties instead of setting them in the constructor
- drop constructors that are redundant to the constructor of the parent class
JakeQZ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only had a brief look at this. Initializing properties to null is not necessary since that is the default, and by convention this is not normally explicitly done.
I found https://stackoverflow.com/questions/13114602/are-parent-constructors-called-if-a-child-class-does-not-define-a-constructor#13114603 which confirms constructors can be removed provided the base class defines one.
- use default values for properties instead of setting them in the constructor - drop constructors that are redundant to the constructor of the parent class
bdf04f4 to
b7989b0
Compare
|
Done and repushed. |
JakeQZ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this works now.
IIRC, the PHP language issue with undefined constructors is when there is a base class with no constructor defined:
- the derived class cannot call
parent::__construct(); - if the base class is later modified to add a constructor to perform an important initialization task, it won't be implicitly called;
- to mitigate against this, the base class should have an empty constructor from the outset, so that the derived class can call it, should it later need to do something.
- (C++ does not have this problem because default constructors are always implicitly called.)
The issue doesn't apply here, since all the removed constructors are in derived classes for which there is a already a constructor in the base class.