i have some file test.php
<?PHP
$config_key_security = "test";
?>
and i have some class
test5.php
include test.php
class test1 {
function test2 {
echo $config_key_security;
}
}
class test1 {
function test2 {
global $config_key_security;
echo $config_key_security;
}
}
or
class test1 {
function test2 {
echo $GLOBALS['config_key_security'];
}
}
Having your class rely on a global variable isn't really best practice - you should consider passing it in to the constructor instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With