Opened 6 years ago
Last modified 6 years ago
#45861 new defect (bug)
Global variable in plugin main file
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | dev-feedback has-patch |
Focuses: | Cc: |
Description
In the main plugin file, if we declare a variable, it will be used as a global variable in WordPress.
This might lead to conflict for global variable names.
The code is in wp-settings.php file.
A simple fix is creating a function to load a plugin and include main plugin file inside that function. So the scope is function scope, not global scope.
Attachments (1)
Change History (5)
#2
@
6 years ago
@rilwis Just create new function to include plugin file is solve the issue you have created? also you have added @return void
in your patch 45861.patch that do not needed as function does not return any return value.
Needs to wait for code developer reply on this ticket
#4
@
6 years ago
@mukesh27 Yes, using a function to include plugin files makes the variables available in the function scope only, which means they're not available in the global scope.
Using @return void
is a valid (it's recommended but not a must) since it's the recommended way to tell developers that the function does not return anything.
Proposed patch