-
Notifications
You must be signed in to change notification settings - Fork 37
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
variables in template files are flagged as global #200
Comments
That's the crux of it: "supposed to". However, there is no guarantee that that's the only way that these files will be loading - think: plugins doing funky stuff -, so it's always better to be safe and prefix the variables, than sorry. |
If it's going to be flagged, maybe Error is too severe. |
This is a problem. If there's no way of detecting whether the variable is global or skipping templates, I'd say we need to disable this for the time being. Otherwise, theme authors will have to whitelist or prefix every single variable used in a template. Even a warning, I believe, will be a hindrance to the TRT's review process because it'd mean additional time checking false-positives. But, I could live with that as a middle ground.
This notice is also not worded correctly. The guideline related to this is more appropriately:
|
Just to be clear: the variables we are talking about here are declared as global variables based on the file alone.
I concur this can do with improvement, but that's something for WPCS. |
We can nitpick over whether the feature is happenstance or intentional, but that doesn't really matter. Personally, I intentionally use this PHP feature to do some pretty cool stuff, like passing data to templates (though I don't generally assign variables in a template). What matters is that the notice is incorrect by the TRT guidelines. The team neither recommends nor requires that such variables be prefixed. Therefore, I'd recommend we disable it for now. |
That's not nitpicking, that's basic understanding of the principles of how PHP works.
I'd like to suggest for this issue to be discussed in a TRT meeting, bearing the above input in mind. |
Which was my point. It simply works like this because that's how PHP works.
Then, this should be a non-issue as far as the TRT is concerned. I was given the impression that it was a default check. If it is not now nor is it planned to become one of the default checks, it's not a high priority.
That's what I was asking for--that we disable the prefixing of global variables part. |
Using it with a prefix is the best way to use it for themes, and that means it gives errors for all the variables in a template file. |
A sniff for this has been merged and will be in the next release (0.2.0). I'll close this to clean up the issues a bit. |
@dingo-d The fix which was merged addresses the |
Oh, I haven't taken that into the account. Reopening and adding the necessary label 🙂 |
I think the WP global variables should still be caught in template files, because that's how the template files work (all the query vars are declared as global where the template is loaded, so that the globals are available). Those global names should not be assigned to in the template file, just like anywhere else, and should get flagged |
Ok, the
What would be an example of an incidental variable? |
I don't see how you would distinguish between a variable that was set using |
A discussion from the triage basically is in agreement with the comment by Juliette:
Also, a comment by @joyously was:
We still don't have the pattern that should be checked, so we need to work on this. |
The theme template files are supposed to be loaded with core functions. When they are, the variables used in them are not global, so do not need to be prefixed.
Each line with a variable is generating an error for
Overriding WordPress globals is prohibited
andVariables defined by a theme/plugin should start with the theme/plugin prefix
.Do we need a whitelist or keep track of which files are used with
include
orrequre
?The text was updated successfully, but these errors were encountered: