Skip to content

Conversation

@cameron1729
Copy link
Contributor

No description provided.

@cameron1729 cameron1729 changed the title Allow use of the superglobal Allow use of the $GLOBALS superglobal Nov 6, 2025
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (642326a) to head (66f09b2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #218   +/-   ##
=========================================
  Coverage     98.27%   98.27%           
  Complexity      994      994           
=========================================
  Files            42       42           
  Lines          2961     2961           
=========================================
  Hits           2910     2910           
  Misses           51       51           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andrewnicols andrewnicols merged commit ead813d into moodlehq:main Nov 6, 2025
13 checks passed
@jrchamp
Copy link
Contributor

jrchamp commented Nov 6, 2025

Use of global variables in general is something I typically discourage these days. There's not much discussion here, so I'm guessing it happened in another forum.

My question: Is $GLOBALS being added here for backward compatibility with existing code? Or are we saying that $GLOBALS is unconditionally allowed by Moodle Coding standards?

Personally, I would recommend temporarily allowing, but discouraging the use of $GLOBALS because access to these values is already available from the global keyword and which serves as a very clear semantic highlight of external dependencies for a method. Then, over years, usage could be phased out and changes to global state could be less problematic.

@andrewnicols
Copy link
Contributor

Hi @jrchamp,

Yes, we do discourage its use, but it is still in use in a few places and automatically fixing it will break things, so we to allow it.

@jrchamp
Copy link
Contributor

jrchamp commented Nov 6, 2025

Perfect! Thank you for confirming.

@cameron1729
Copy link
Contributor Author

cameron1729 commented Nov 7, 2025

Worth noting: the sniff says nothing about whether you should use $GLOBALS or not. PHPCS simply reports that $GLOBALS should be lower case - which if course it shouldn't be; and if you followed the advice and changed it, your code would break.

@jrchamp
Copy link
Contributor

jrchamp commented Nov 7, 2025

@cameron1729 Excellent point! 🧠 In that sense, this sniff should include all of the special variables from both PHP itself and Moodle core. I can't begin to thank you for highlighting that note. ❤️

As far as discouraging use, I agree that seems that would be a different Sniff. Perhaps something new like moodle.PHP.DeprecatedVariables. Either way, that's probably something that should be its own issue.

@cameron1729
Copy link
Contributor Author

No worries @jrchamp - happy to help :)

I think a new sniff makes sense too. Maybe part of the moodle-extra coding style.

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.

3 participants