Stop disabling super globals

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Registered User
Posts: 7
Joined: Thu Apr 23, 2015 10:34 pm

Re: Stop disabling super globals

Post by JWPlatt » Mon Apr 27, 2015 3:52 pm

DavidIQ wrote:There are quite a few extensions that do this but you can check how it's done in this one and do something similar:
Sorry, I've lost the context here. To what "this one" do you refer?
DavidIQ wrote:
Also, can you give me, or point me to, a code sample of how to use the $config array?
Same way you'd use any other PHP array: $config['whatever_config_key']
Thanks for addressing all my questions. Awesome. You said the $config array can change per application, but do you have a link to a good example of it's use?

I'd like to point out here for future readers and for those with such issues, but have little familiarity with the phpBB platform, that code samples posted by phpBB devs are not always obvious or as complete as believed necessary. So, for example, the above snippet needs more because it is not obvious to the casual integrator that the complete snippet really is this:

Code: Select all

global $config
$foo = $config['whatever_config_key']
I've seeen a number of posts where this omission was confusing. And, in fact, I incorrectly tried to instantiate a new $request class, as discussed above, instead of correctly declaring a global to bring it into scope. I've seen others asking for help after trying to instantiate other classes such as $user.

I would urge phpBB devs to be more specific to avoid confusion because we're not all as familiar as the devs with the ins and outs of phpBB, or even php generally.

Thanks again.

Registered User
Posts: 1
Joined: Mon Oct 31, 2016 12:01 am

Re: Stop disabling super globals

Post by Darkseal » Mon Oct 31, 2016 12:05 am

Trying to stick to best-practice is what I always do in most cases: however, there are some rare scenarios when using the request class isn't possible, for example when you're dealing with existing, pre-3.1 phpBB implementations and you want to upgrade the forum without having to mess with a PHP script that you either don't own, know or are allowed to change.

When such situations arise, phpBB 3.1.x gives you the chance to re-enable superglobals either globally or programmatically:

Open the /phpbb/config/parameters.yml file and change the core.disable_super_globals key from true to false.

This is a sample code that can be used to temporarily enable superglobals (per-request scope):

Code: Select all

// temporarily enable superglobals

// TODO: do your stuff here.

// disable superglobals again
You can also read this post for further info about this topic, such as how to do this when you're upgrading from phpBB 3.0.x or below.

User avatar
Registered User
Posts: 737
Joined: Tue Nov 01, 2005 9:50 pm
Location: Milano (I) Frankfurt (D)

Re: Stop disabling super globals

Post by 3Di » Mon Oct 31, 2016 8:25 am

If you really need it and you can't avoid that then go (just) for the "programmatically way of doing it".

Forget to hack the core code, it is a no-no. :geek:
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
Customisations Team Leader
Customisations Team Leader
Posts: 1787
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth

Re: Stop disabling super globals

Post by DavidIQ » Mon Oct 31, 2016 12:15 pm

I recently had to use $request->enable_super_globals(); for a WordPress script I was integrating into a phpBB site because, of course WordPress uses all sorts of super globals throughout their code so there was no going around it. As 3Di said, the programmatic way is probably the best way to do it. Enable them for what you need it and then disable them right after.

Post Reply