global-variables

How to programmatically set a global (module) variable?

I would like to define globals in a "programmatic" way. Something similar to what I want to do would be: definitions = {'a': 1, 'b': 2, 'c': 123.4} for definition in definitions.items(): exec("%s = %r" % definition) # a = 1, etc. Specifically, I want to create a module fundamentalconstants that contains variables that can be acc...

Global variables in PHP?

Does PHP have global variables that can be modified by one running script and read by another? ...

PHP best practices: repass variables from config file when calling functions or use global?

I have a program that I use on several sites. It uses require('config.php'); to set any site dependant variables like mysql connect info, paths, etc. Let's say that I use one of these site-dependant variables in a function, like $backup_path. This variable was initially declared in config.php, and does not appear in the main program fi...

C++ singleton vs. global static object

A friend of mine today asked me why should he prefer use of singleton over global static object? The way I started it to explain was that the singleton can have state vs. static global object won't...but then I wasn't sure..because this in C++.. (I was coming from C#) What are the advantages one over the other? (in C++) ...

Global variable in Qt, how to?

I'm using Qt and in the main method I need to declare an object that I need to use in all my other files. How can I access that object in the other files? (I need to make it global..) I'm use to iPhone development and there we have the appDelegate that you can use all over the application to reach objects you've declared in applicationD...

php $GLOBALS variables

I'm writing a bit of the code and I have parent php script that does include() and includes second script, here is snippet from my second code: echo ($GLOBALS['key($_REQUEST)']); I'm trying to grab a key($_REQUEST) from the parent and use it in child, but that doesn't work.. this is when I run script using command line: mbp:digawe...

global variable approach in C# Windows Forms app? (is public static class GlobalData the best)

Hi, I want to have some custom configuration (read in from file) available throughout my C# windows forms application. Is the concept of say: creating a static class, e.g. "public static class GlobalData" loading from from the "Load" action of the main form event How does this sound? Is this the best practice way to do it? ...

How do you localize a number of legacy globals without eval?

I'm asking this question because I finally solved a problem that I have been trying to find a technique for in a number of cases. I think it's pretty neat so I'm doing a Q-and-A on this. See, if I could use eval, I would just do this: eval join( "\n" , map { my $v = $valcashe{$_}; sprintf( '$Text:...

How to compile multiple files together with ml in assembly x86?

Hi, I'm working in x86 assembly in 16bits. I have three files that need to share 'variables between them' - basically, the data segment. When I compile them, as in the following: ml file1.asm,file2.asm,file3.asm io.lib They cannot access each other's variables How do I share a data segment, and thus variables between the files? Thank ...

Are global variables in PHP considered bad practice?

function foo () { global $var; // rest of code } In my small PHP projects I usually go the procedural way. I generally have a variable that contains the system configuration, and when I nead to access this variable in a function, I do global $var;. Is this bad practice? ...

How/where to release global variables in objective c? -iphone

I have gone through the following question. http://stackoverflow.com/questions/1528696/objective-c-where-do-you-dealloc-global-static-variables But the question is related on static variables. It has something different situation then mine. I have following code in application. //.h file #import "cocos2d.h" #import "something.h" #imp...

Global Variables in a WordPress Plugin

I am trying to create my first WordPress plugin. Even in trying to create the install function, things are being a pain. I want to set some global variables specific to my plugin rather than putting the literal values throughout the various functions. However, my install function does not pick up these global variables. Here is my code s...

codeigniter, global variable for beta project path, and access from everywhere.

Hi friends, I use CodeIgniter, I'm happy with that, but I have a question. I build my projects under /www/projectname/beta/... directory, so at my code, at many parts like including some images or css files or etc. I have to make ... src="/projectname/beta/... so when I complete the website, I need to edit so many pages to clear these...

Instantiating at global level (C++)

Hi, I get the following error with the code below. expected constructor, destructor, or type conversion before '=' token -- #include <string> #include <map> class Foo { }; std::map<std::string, Foo> map; map["bar"] = Foo(); int main() { return 0; } ...

Logging events in Python; How to log events inside classes?

Hello guys. I built (just for fun) 3 classes to help me log some events in my work. here are them: class logMessage: def __init__(self,objectName,message,messageType): self.objectName = objectName self.message = message self.messageType = messageType self.dateTime = datetime.datetime.now() def...

Global variables in Objective C on iPhone

I am new to Objective C with a background primarily in database programming. I am developing an iPhone medical application that involves multiple formulas for calculations, using many variables. Essentially each formula will have its own screen, but numeric entries and calculations from each screen should appear on the screens for other ...

Global variables v Settings in C#

I have read in various places that having variables with global scope, i.e. a public static class with static members, is considered going against the philosophy of OO, and is not good design. (For example, I have seen comments along the lines of: "If you are using a global, you are not doing it right." Or words to that effect.) But, if...

Share global logger among module/classes

What is the best (proper) way to share a logger instance amongst many ruby classes? Right now I just created the logger as a global $logger = Logger.new variable, but I have a feeling that there is a better way to do this without using a global var. If I have the following: module Foo class A class B class C ... class Z end ...

Am I using a global state here, is there any better way to do this?

I am modifying some legacy code. I have an Object which has a method, lets say doSomething(). This method throws an exception when a particular assertion fails. But due to new requirement, on certain scenarios it is okay to not throw the exception and proceed with the method. Now I am not calling this method directly from the place whe...

How to reference base URLs for images in XAML in Silverlight?

I have images scattered throughout my silverlight app, and because of the structure we decided on, all images are brought in from an HTTP URL. Currently, in XAML an image would be declared as follows: <Image Source="http://www.example.com/directory/example.png" /> I would like the base URL for all images referenced stored in a global...