I've built many sites over the last 10 years and NEVER used Global. Is it still valid, or does it belong in php5.3
Redit post from 7 years ago
https://www.reddit.com/r/PHP/comments/2lct7y/question_do_you_use_globals_or_not/
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I got a strange behavior in a Laravel project. I reduce my code and get this strange result.
Laravel 8 / PHP Version 7.4.21
The code
<?php
$v='aaa';
echo "v = ",$GLOBALS['v'] ?? "KO","<br>";
MyFct('Test2');
phpinfo();
exit;
function MyFct($txt) {
global $v;
echo "v=$v<br>";
echo "v = ",$GLOBALS['v'] ?? "KO","<br>";
}
The result
v = KO aaa expected
v= aaa expected
v = KO aaa expected
I expected to find st in the phpinfo but I can't figure out which parameter could produce this ...
I tested this code in cli, it works fine.
More tests
Explanation
Please or to participate in this conversation.