Search code examples
phpphpbb

PHP global variables null inside function if not already defined


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?


Solution

  • 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.