I am having problems with some legacy code that I am trying to add to a Yii project.
It has to do with global variables, which I am well aware should instead be passed as parameters, but since this old code and is used in other projects rewriting it is not really and option.
$testVar = '123';
function testOutput() {
global $testVar;
var_dump($testVar);
}
testOutput();
Now if I include this file in a plain php file it works and outputs
string '123' (length=3)
But if I include this file in a Yii controller or even in a template it output this
null
I have tried to search for this issue but I just get a bunch of results about people using global variables incorrectly. I am sure it is not actually a Yii issue but most likely a php_ini setting that Yii is setting, but I can't find anything when searching the code or the Yii docs that would explain this.
This example can be tested by just creating a file with my first code block and then include it into a Yii template or controller. I even tested it with a clean example Yii project.
I hope I didn't hurt my chances of figuring this out by tagging this questiong with Yii since I have a feeling that it is not just a Yii specific issue.
Any insights would be greatly appreciated.