Skip to content
Advertisement

Include files from function

I am trying to include a file from a function. This function doesn’t return anything, it is just initializing many things.

This function also apply the language so I need to include the language file. But it seems like the scope isn’t the same.

How can I include a file from a function as global ?

Ex :

function StartUp() {
    include('test.php'); // I want to make the vars in test.php available in a Global Scope.
}

Advertisement

Answer

You cannot include external files in the function and make all the vars global in it because if you do so they remain the in scope of that function only, better way you just include them by a simple way without any function.

Or you can just add a global keyword in front of your all variables to make them global all over.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement