Page MenuHomePhabricator

Replace stringified classes with ::class
Open, Needs TriagePublic

Description

mediawiki-config is full of "\\Foo\\Bar\\Baz"... We should tidy them up with \Foo\Bar\Baz::class

https://codesearch.wmcloud.org/search/?q=%5C%5C%5C%5C%5BA-Za-z%5D%2B%5C%5C%5C%5C&files=php&excludeFiles=&repos=operations%2Fmediawiki-config

Event Timeline

Change 593654 had a related patch set uploaded (by Reedy; owner: Reedy):
[operations/mediawiki-config@master] Replace stringified class names with ::class

https://gerrit.wikimedia.org/r/593654

Change 593654 merged by jenkins-bot:
[operations/mediawiki-config@master] Replace stringified class names with ::class

https://gerrit.wikimedia.org/r/593654

I am not sure what is the benefit of using ::class when we have a fully qualified class name.

::class causes a class name resolution to resolve the namespaces ( https://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class ). I would assume that it might add a little bit of overhead. If the intent is primarily to drop the double backslashes, maybe we can use a single quoted string: '\Foo\Bar\Baz'?

Then if there is a typo, I would guess Phan will catch it when we are using ::class so that is an advantage.

It also helps with Codesearch and IDEs as it will match the standard name of the class, whereas we generally do not attempt to search for slash-escaped strings that mention a class.

A few more remaining to be converted:
https://codesearch.wmcloud.org/operations/?q=%5B%27%22%5D(%5BA-Za-z%5D%2B)%3F%5C%5C%5C%5C&i=nope&files=php%24&excludeFiles=&repos=Wikimedia%20MediaWiki%20config

Krinkle updated the task description. (Show Details)
Krinkle updated the task description. (Show Details)
Krinkle added a project: good first task.

Claiming for our on-boarding. This will be a good one to get familiar with our deployment process (Logstash, mwdebug staging, etc.) without (yet) involving MediaWiki specifics beyond PHP itself.

I suspect there's probably a few non namespaced ones hanging around in there too, which makes them harder to find (and part of the reason for this task in the first place).

Change 990711 had a related patch set uploaded (by Reedy; author: Reedy):

[operations/mediawiki-config@master] CommonSettings: Swap stringified class names in ConfirmEdit usages

https://gerrit.wikimedia.org/r/990711

Change 990766 had a related patch set uploaded (by Reedy; author: Reedy):

[operations/mediawiki-config@master] wmf-config: Replace numerous stringified classes with use statements

https://gerrit.wikimedia.org/r/990766

Change 990711 merged by jenkins-bot:

[operations/mediawiki-config@master] CommonSettings: Swap stringified class names in ConfirmEdit usages

https://gerrit.wikimedia.org/r/990711

Change 990766 merged by jenkins-bot:

[operations/mediawiki-config@master] wmf-config: Replace numerous stringified classes with use statements

https://gerrit.wikimedia.org/r/990766