Welcome Guest, Not a member yet? Register   Sign In
My globals are toasted. Is this global warming?
#1

[eluser]steward[/eluser]
Recently upgraded from php4 to 5.

Have a great CI site but want to start tweaking it more now.

Prefer to share a config file with other apps, via the php shared script directory.

Nothing fancy, just a few globals.

Er, whatever happened to globals?


Code:
$a=array();
funtion foo()
{
  global $a;
  return $a['fie'];
}

or

Code:
$GLOBALS['foo']['fie']='fred';

Either solution would do for me.
But I think there may be something funny going on within the CI engine.
Having a simple global is turning into a tricky proposition.

Can any expert sense my pain, and direct me to a script, sample, link that would give an explanation or provide the preferred method?

I'm not Dijkstra or Pascal. I've got other apps to share with.
Please no rocket science. Just a global that is really global.

Many thanks.
#2

[eluser]TheFuzzy0ne[/eluser]
Where exactly are you setting and accessing the global variable? Is there any reason it can't be kept within a model method, or within the scope of the CodeIgniter Super Object? Since CodeIgniter is object oriented, and has a good config library, I don't ever find I need globals, as there's usually a much better, more logical place to store the variable.

With that said, globals should still work without any problems. I can only suppose that that global variable isn't really in the global scope.
#3

[eluser]steward[/eluser]
Of course.
I am inside config.php, and thus outside global scope.
Thank you for the assist.

======================================
It is against the OOP grain, but it's a real-world situation.
At first glance, I would need to add my require_once('shared.php') to

system/CodeIgnitor.php or
config/constants.php

Not ideal but what can I do?

My file is global in the "meta global" sense that it provides information to my CI apps, and many others. My subdomains are spread across a number of separate servers, and not all apps are developed in CI. All they have in common is php.

Yet they have a need to know about one another, for cross-domain operations such as user authentication and selection of video servers. By placing a small script in a shared location (defined in php.ini) that is the same on all servers, I can use SVN and reduce the number of places I need to remember to update when my "meta config" data changes.

Now however, I will need to remember this hack when updating the CI core.
Win some lose some...




Theme © iAndrew 2016 - Forum software by © MyBB