I need to change a global variable inside a namespace in PHP.
I'm currently refactoring some legacy code and a section of the code relies on the use of a global variable, which used to be configured in the code I'm refactoring.
I'm now trying to use namespaces on the new refactored code and can access the variable just fine by using \
, but I couldn't find a way to change its value.
Sadly, changing the \legacyCode so it doesn't use the global variable is out of question.
Is not using namespaces here the only good solution?
Example:
namespace Namespace;
$GlobalVariable = 123;
abstract class NamespaceClass extends \legacyCode
{
}
// no namespace defined
class legacyCode
{
function doSomething() {
global $GlobalVariable;
echo $GlobalVariable;
// GlobalVariable is undefined
}
}
Thanks in advance.