In a controller or model class, variables are not global.
It is bad practice to use global variables, so there is no place to use global variables in CI4.
But if you want to use global variables, you could use because that is a PHP language feature.
You need to make it global explicitly.