Skip to content
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

Conversation

schlessera
Copy link
Contributor

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 use self:: and private methods), extending them will lead to unexpected results and hard-to-diagnose bugs. self:: and private should only be used in final 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:

  • some classes were already changed from non-extensible to extensible in prior changes, so I suppose this is a wanted use case
  • some classes have quite a bit of logic to them, and keeping them extensible avoids completely rewriting some of these

Related issue: #231

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.
@oscarotero oscarotero merged commit c51ac33 into php-gettext:master Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants