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.
JWPlatt
Registered User
Posts: 7
Joined: Thu Apr 23, 2015 10:34 pm

Re: Stop disabling super globals

Post by JWPlatt »

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.

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

Re: Stop disabling super globals

Post by Darkseal »

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:

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

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

Code: Select all

// temporarily enable superglobals
$request->enable_super_globals();

// TODO: do your stuff here.

// disable superglobals again
$request->disable_super_globals();
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
3Di
Registered User
Posts: 951
Joined: Tue Nov 01, 2005 9:50 pm
Location: Milano 🇮🇹 Frankfurt 🇩🇪
Contact:

Re: Stop disabling super globals

Post by 3Di »

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:
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades

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

Re: Stop disabling super globals

Post by DavidIQ »

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

Post Reply