Skip to content

Performance: use FQN for global constants#783

Merged
wimg merged 1 commit intomasterfrom
feature/use-FQN-constant-names
Dec 31, 2018
Merged

Performance: use FQN for global constants#783
wimg merged 1 commit intomasterfrom
feature/use-FQN-constant-names

Conversation

@jrfnl
Copy link
Copy Markdown
Member

@jrfnl jrfnl commented Dec 31, 2018

As there are no sniff PRs open at the moment, this felt like as good a time as any to make this change ;-)

Constants in PHP are namespaced as well, however, when PHP cannot find the constant in the namespace, it will fall through to the global namespace.

The step to first check within the namespace can be skipped by either using use const ... (PHP 5.6+) or by prefixing the constant with a \.

As PHPCompatibility uses a lot of global constants, some performance gain can be archived by using the FQN for constants.

This PR implements this throughout the codebase.

If we want to guard this for the future, we could add the SlevomatCodingStandard as a dev dependency and add the SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants sniff to the PHPCompatibility native ruleset.

Constants in PHP are namespaced as well, however, when PHP cannot find the constant in the namespace, it will fall through to the global namespace.

The step to first check within the namespace can be skipped by either using `use const ...` (PHP 5.6+) or by prefixing the constant with a `\`.

As PHPCompatibility uses a lot of global constants, some performance gain can be archived by using the FQN for constants.

This PR implements this throughout the codebase.

If we want to guard this for the future, we could add the SlevomatCodingStandard as a `dev` dependency and add the `SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants` sniff to the PHPCompatibility native ruleset.
@jrfnl jrfnl added Type: chores/QA PR: quick merge PR only contains relatively simple changes PR: ready for review labels Dec 31, 2018
@jrfnl jrfnl added this to the 9.x Next milestone Dec 31, 2018
@wimg wimg merged commit 4487042 into master Dec 31, 2018
@wimg wimg deleted the feature/use-FQN-constant-names branch December 31, 2018 15:58
@jrfnl jrfnl removed the PR: quick merge PR only contains relatively simple changes label Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants