[wp-trac] [WordPress Trac] #45861: Global variable in plugin main file
WordPress Trac
noreply at wordpress.org
Mon Jun 23 10:09:53 UTC 2025
#45861: Global variable in plugin main file
------------------------------------+------------------------------
Reporter: rilwis | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: normal | Resolution:
Keywords: dev-feedback has-patch | Focuses:
------------------------------------+------------------------------
Comment (by rilwis):
Hi @callumbw95,
Thanks for your feedback. You're right about the potential breakage of
code if plugin developers intentionally expose the global variable **just
by declaring it in the main plugin file**.
I have no stats about this. It's just my personal opinion and observation
that some plugin developers put their random variables in the main plugin
files, and that can cause garbage in the global scope, and also
**potentially break other plugins' functionalities** if they share the
same names.
If plugin developers want to make a variable global, it's best if they
declare it explicitly via `$_GLOBAL['my_plugin_slug'] = ...`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45861#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list