FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Bug Reports » Problem with FUDforum API global variables (Global variable visibility issue when GLOBALS.php outside global scope)
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Problem with FUDforum API global variables [message #161922] Sun, 21 February 2010 03:31 Go to next message
jlundan is currently offline  jlundan
Messages: 4
Registered: February 2010
Location: Finland
Karma: 0
Junior Member
Hi,

I just started using the FUDApi and I ran to a small problem. It seems that FUDApi uses a bunch of global variables which are defined in GLOBALS.php and which should be included before using the FUDApi.

The GLOBALS.php expects to be run in global scope because it does not use either global keyword or $GLOBALS array while defining its variables. In other words, GLOBAL.php uses format:

$FUD_OPT_1 = 1737422013;

instead of for example

$GLOBALS['FUD_OPT_1'] = 1737422013;

The problem comes when I try to include the GLOBALS.php from inside a framework, such as CodeIgniter. In these cases my code is already inside a framework class or a method and I cannot go out of it. This means if I include the GLOBALS.php, the variables inside it are no longer global scoped but inside the scope of my framework class/method.

This causes FUDApi to crash with error message like "undefined index 'FUD_OPT_1'. The problem can be solved by modifying the GLOBALS.php to use $GLOBALS array.
Re: Problem with FUDforum API global variables [message #161926 is a reply to message #161922] Sun, 21 February 2010 08:23 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
If you include GLOBALS.php in global scope of the script you can reference its variables as $GLOBALS['...'] in local scope. See example at http://php.net/manual/en/reserved.variables.globals.php
Re: Problem with FUDforum API global variables [message #161927 is a reply to message #161926] Sun, 21 February 2010 08:45 Go to previous message
jlundan is currently offline  jlundan
Messages: 4
Registered: February 2010
Location: Finland
Karma: 0
Junior Member
Yes, but that's not quite what I am after. I'll try to reprhase:

My point is that as far as I understand: currently GLOBALS.php *must be* run in the global scope in order core.inc to work. (Sorry, I previously talked about FUDapi requiring it, but it seems that it is core.inc that crashes.)

Line 60 (in my installed version) of core.inc contains

if ($GLOBALS['FUD_OPT_3'] & 4194304) {	// Plugins enabled


which tries to read global variable FUD_OPT_3. Because I use a PHP framework, I might not be able to include GLOBALS.php from global scope (like in my current project). This means that FUD_OPT_3 is no longer global variable and core.inc cannot find it. If variables in GLOBALS.php would be declared using the $GLOBALS variable like I suggested, I could include the GLOBALS.php from inside a PHP framework class as well.

I dont know if this is actually a bug or an enhancement, but I hope this clarifies my issue bit more.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Query failed: ERROR: value too long for type character varying(100)
Next Topic: FUDApi - fetch categories
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 12:39:27 GMT 2024

Total time taken to generate the page: 0.01923 seconds