Skip to content

Remove global from litespeed-cache.php #837

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

Merged
merged 4 commits into from
Jun 26, 2025
Merged

Conversation

szepeviktor
Copy link
Contributor

Avoiding adding a new global at all cost.

@hi-hai
Copy link
Collaborator

hi-hai commented Jun 25, 2025

This branch has conflicts that must be resolved

@hi-hai hi-hai marked this pull request as draft June 25, 2025 19:29
@szepeviktor szepeviktor marked this pull request as ready for review June 25, 2025 19:56
@szepeviktor
Copy link
Contributor Author

Resolved 🍏

@@ -46,11 +45,10 @@
* @since 5.2 Auto correct protocol for CONTENT URL
*/
$WP_CONTENT_URL = WP_CONTENT_URL;
$site_url = site_url('/');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling function twice costs more than a var. Why drop this assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All is in the title.
Because this adds a new global variable to WordPress.

Copy link
Collaborator

@hi-hai hi-hai Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't L48 $WP_CONTENT_URL similar?

Copy link
Contributor Author

@szepeviktor szepeviktor Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, it is! $WP_CONTENT_URL

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to unset. How do you think this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.
Actually I am paralyzed when meeting PHP 4 technology. PHP 5 introduced namespaces: 1 July 2004

Here is my What to avoid list.

  • ❌ Global constants
  • ❌ Global functions
  • ❌ Classes without namespace
  • ❌ Loading PHP files with require
  • ❌ Code with side-effects outside the main file
  • ❌ Immediate execution without add_action in the main file
  • ❌ Conditional function or class definitions

source

@hi-hai hi-hai merged commit db3f4c6 into litespeedtech:dev Jun 26, 2025
1 check passed
@szepeviktor szepeviktor deleted the patch-1 branch June 26, 2025 19:57
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.

None yet

2 participants