Hi all,
background: i'm tweaking the phpnuke 6.0 core, so the admin permissions are registered as MySql records rather than in the filesystem
Platform is: W2K, Apache 1.3.27, PHP 4.2.3 with register_globals = On
(short) the problem: after the tweak some variables dissapear (set but empty) inside functions, in spite of being declared as globals inside them and being set and assigned right before the function call.
function whatever(){
global $x;
echo $x; --------------->doesn't work
print_r(get_defined_vars()); ---> shows $x is set, but empty
}
switch($op){
case "whatever":
$x =1;
echo $x; -----------------> it works right before the call!
whatever();
break;
}
(long) the problem:
PHPNuke has a quite messy and inflexible method of assigning perms to admins and building the control panel. It's based on a single file (admin.php) that receives always receives at least a $op variable (via $_GET) . Depending on the value of $op it will switch and include one of a set of files, which will in turn switch again and call the destiny function for that op. (Lost already? 🙂)
My alternate system is built around three tables and two php functions:
the tables: one of them "describing" the admin modules (name, id, default op, icon, etc..); another one relating admins to their allowed modules and another one relating one or many $ops to the correspondent module.
the functions: one of then acts as the switcher in admin.php; it receives the op and picks the corresponding file, then includes it. The other function resides in the header of every included module and check if your admin id is allowed to that module.
Everything is working alrigth for about 80% of use cases. The big bummer is that sometimes variables are lost the way show above in the individual module files. As an extra creepy feature, everything is OK if i declare the variable global at the very start of the included file (before it being even assigned)
I tried to pass an array with all defined vars to my switcher function and extract() it right before including the file. Still doesn't work.
I know it's a very general description of a very abstract problem and my english is not that good, but any, i mean any (PHP bug, globals misunderstanding, plain idiocy of mine) hint would be hugely appreciated