Jump to content

Resolved - Add New Admin


bsmither

Recommended Posts

Well, my problem is certainly something I did -- it's not a bug in CubeCart -- although I'm not too sure about the administrator management code either.

 

It's really strange how the CubeCart PHP code is behaving on my development machine. A backup copy of CC522 is working fine.

Link to comment
Share on other sites

Since I usually flounder around making all kinds of mistakes, I have managed to undo damage a few times by renaming and replacing whole directories, like classes, with a known good copy. Once I know which directory has the issue I can usually find the problem as I narrow it down to only the most recently modified files. Very Down and Dirty, and of course I don't make as many experimental changes as you do in the process of helping others, so I have fewer recently modified files.

Link to comment
Share on other sites

I found the problem. It is a case of my not realizing a side-effect of how PHP can and does express global variables.

 

There are variables in a global scope (outside of functions) and there are Super-Globals, which can be seen everywhere.

 

I have been working on an experiment where I was using the typical method of instantiating classes and assigning that class to a Super-Global. For example, here are statements the instantiate common classes needed to run CubeCart. The instances are assigned to the Super-Global array, $GLOBALS (a reserved variable name in PHP):

$GLOBALS['cache'] = Cache::getInstance();
$GLOBALS['db'] = Database::getInstance($glob);
$GLOBALS['config'] = Config::getInstance($glob);
$GLOBALS['debug'] = Debug::getInstance();
$GLOBALS['session'] = Session::getInstance();

and others.

Naturally, one would therefore use this to instantiate the admin class:

$GLOBALS['admin'] = Admin::getInstance();

 

Not so fast.

 

It seems that PHP will also make these instances of classes available with the respective global variables:$cache, $db, $config, $debug, $session, $admin, and all the others.

 

So, if PHP is executing code in the global scope - not inside a function - as it is with many of the files in the admin/source folder, one cannot use any of the above variables. And yet, the Create New Admin portion of the settings.admin.inc.php file does that very thing.

 

Conclusion: In the case of the Admin class, one must never assign the instance to $GLOBALS['admin'], but rather always communicate with the instance as Admin::getInstance(), because CubeCart may use the variable $admin elsewhere (in a global scope). Until that maybe changes in a future version.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...