#2299 - Refactor some use of global variables

Identifier #2299
Issue type Feature request or suggestion
Title Refactor some use of global variables
Status Completed
Tags

Risk: Core rearchitecting (custom)

Handling member Chris Graham
Addon core
Description Some people will hate that we use global variables, but I honestly think this is better than passing context parameters through a massive call tree, or implementing complex singleton/manager/static-class kinds of system. Globals are simpler (easier to understand, better performance, less code overhead), especially for cases where we're just setting simple state toggles.

However, we should not let this make our code tidy. We already insist on using phpdoc against every global used in more than a small number of places.

We still have a case where we toggle some state variables temporarily on then off. It's an ugly code pattern...

$dbs_bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
$GLOBALS['NO_DB_SCOPE_CHECK'] = true;
...
$GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_bak;

This would be better as...

push_db_scope_check(false);
...
pop_db_scope_check();


I've identified (via careful code grepping) these globals we should handle via functions:
- NO_DB_SCOPE_CHECK
- SUPPRESS_ERROR_DEATH
- LAX_COMCODE
- NO_LINK_TITLES
- NO_QUERY_LIMIT

NO_QUERY_LIMIT should reset the query limit to what it was when popped.
Steps to reproduce

Funded? No
The system will post a comment when this issue is modified (e.g., status changes). To be notified of this, click "Enable comment notifications".

Rating

Unrated