-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Support late static binding across all classes #232
Merged
oscarotero
merged 37 commits into
php-gettext:master
from
schlessera:replace-self-with-static-in-extendable-classes
Oct 22, 2019
Merged
Support late static binding across all classes #232
oscarotero
merged 37 commits into
php-gettext:master
from
schlessera:replace-self-with-static-in-extendable-classes
Oct 22, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The class is an abstract base class and the `$current` is `public static`. Accessing it via `static::` instead of `self::` makes sure an extending class won't inadvertently create an alternate dynamic variable `$current` if it overrides `BaseTranslator::register()`.
Accessing its methods via `static::` instead of `self::` makes sure that method overrides in extending classes will be respected. Also makes its properties protected instead of private, to avoid dynamic redeclaration in extending classes.
Use `static::` instead of `self::` and make the private methods protected instead. This avoids the trait breaking if it is used in a base class that will be extended, and one of the trait methods is extended as well. This is a safer default for traits in general.
Use `static::` instead of `self::` and make the private methods protected instead. This avoids the trait breaking if it is used in a base class that will be extended, and one of the trait methods is extended as well. This is a safer default for traits in general.
Use `static::` instead of `self::` and make the private methods protected instead. This avoids the trait breaking if it is used in a base class that will be extended, and one of the trait methods is extended as well. This is a safer default for traits in general.
Make the private methods protected instead. This avoids the trait breaking if it is used in a base class that will be extended, and one of the trait methods is extended as well. This is a safer default for traits in general.
Use `static::` instead of `self::` and make the private methods protected instead. This avoids the trait breaking if it is used in a base class that will be extended, and one of the trait methods is extended as well. This is a safer default for traits in general.
Having a non-final class with private methods is problematic. In this case, overriding `saveGettextFunctions()` would make `deconstructArgs()` inaccessible and break.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
Also turn `private` method into `protected` method. This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
Also turns `private` methods into `protected`. This avoids extending classes unexpectedly breaking.
Also turns `private` methods into `protected`. This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
Also turns `private` methods into `protected`. This avoids extending classes unexpectedly breaking.
Also turns a `private` method into `protected`. This avoids extending classes unexpectedly breaking.
Also turns a `private` method into `protected`. This avoids extending classes unexpectedly breaking.
Also turns `private` methods into `protected`. This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
This avoids extending classes unexpectedly breaking.
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The classes have a mixture of practices right now which make them very tricky to extend.
All classes seem to communicate they can be extended (i.e. they are not marked as
final
), but as most of them don't properly support late static binding (they useself::
andprivate
methods), extending them will lead to unexpected results and hard-to-diagnose bugs.self::
andprivate
should only be used infinal
classes, or, in more rare cases, when an extension should specifically not have access to some part sof the base class.The solution is to either mark all of them as
final
(provided there is an underlying interface), or make sure they properly support extension.I've opted for the second option in this PR, for the following reasons:
Related issue: #231