• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

PHP global includes

ScottSwing

Gawd
Joined
Jun 9, 2010
Messages
590
My problem:
Code:
<?

include 'file.php';

function f()
{
}

?>


I want all of my classes and variables in file.php to be available to f(). How do I do this?
 
the $GLOBALS superglobal array for global variables, the classes should be available regardless.
 
Why not just declare them global at the beginning of the function?

Code:
function f() {
   global $variable;
}
Or pass specific variables into the variable through its parameters?

php.net is your friend.

and yes, classes are available in any function. But you may need to define the class object as global in that function. Unless you're creating it from within the function.
 
Back
Top