1

It's been several years since I've messed with PHP. But now I'm trying to do phpBB Sessions Integration following this guide: phpBB Sessions Integration. The thing is, it won't work unless I go and define all the globals the phpBB app needs because they end up being null at runtime inside the functions.

So the code in the linked guide only works when I add this line of php code above it:

global $_SID, $auth, $cache, $config, $db, $phpbb_root_path, $phpEx, $SID, $template, $user;

This isn't optimal since I'll have to keep updating this global declaration each time a new global variable is introduced into the phpBB codebase. :( Is there some kind of php ini setting that I should tweak or something to make it to where I don't have to declare these?

3
  • Surprise, this is how PHP works. Using global variables is already a bad thing, why do you want to make it easier to use them? Oh... I almost forgot. The answer to your question is: no. Commented Mar 26, 2017 at 23:41
  • Using globals will probably lead to more problems, you should pass them as arguments to the function instead. Commented Mar 26, 2017 at 23:45
  • 1
    axiac's comment is what makes SO such a great community. Commented Mar 27, 2017 at 0:16

1 Answer 1

1

This was how PHP worked :-) This guide is outdated. It was posted Oct 08, 2007. I am agree with you, using global variable is not optimal. I don't have solution, you have to declare these in each function (and protect your variables). If solutions existed, the community would use them. Some contributors purpose to package all of them in a super variable. But it was rejected (too dangerous, too slow, etc.)

Are you still using php3.0 ? If you want to improve the quality of code, you should upgrade your forum to version 3.2. The new system (using extensions) is very good and based on Symfony's Dependancy Injection.

Here is the guide to explain extension.

It is a bit complex to understand, so here is a very good extension to use in development environment.

Install it and follow steps to get a "skeleton code". You only have to edit it to implement your model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.