3 questions about extern used in an Objective-C project

1) you’re specifying its linkage. extern linkage allows you or any client to reference the symbol. regarding global variables: if the variable is mutable and/or needs proper construction, then you should consider methods or functions for this object. the notable exception to this is NSString constants: // MONClass.h extern NSString* const MONClassDidCompleteRenderNotification; // MONClass.m NSString* … Read more

Changing a global variable from inside a function PHP

A. Use the global keyword to import from the application scope. $var = “01-01-10”; function checkdate(){ global $var; if(“Condition”){ $var = “01-01-11”; } } checkdate(); B. Use the $GLOBALS array. $var = “01-01-10”; function checkdate(){ if(“Condition”){ $GLOBALS[‘var’] = “01-01-11”; } } checkdate(); C. Pass the variable by reference. $var = “01-01-10”; function checkdate(&$funcVar){ if(“Condition”){ $funcVar … Read more

How to define global functions in PHP

If you want your function to always be available, without including it, do this: Create your function in a PHP file. In your php.ini file, search for the option auto_prepend_file and add your PHP file to that line, like this: `auto_prepend_file = “/path/to/my_superglobal_function.php”` Or if you write it with a non absolute path, like this: … Read more

Declaring global variable with php.ini

It’s not possible to set user-level variables within a plain php.ini file (or the .htaccess equivilents). There are some PECL modules that do allow that, such as hidef (http://pecl.php.net/package/hidef) – though these would need to be installed on every installation you use. Including (or pre-including) a file with auto_prepend_file is quite possible – though that … Read more

PHP global or $GLOBALS

Well, you should only use globals in limited circumstances, but to answer your question: global is potentially marginally faster (it will rarely make a difference). $GLOBALS (not $GLOBAL) is more readable, because every time you see it, you know you are accessing/changing a global variable. This can be crucial in avoiding nasty bugs. Inside the … Read more

Static global variables in C++

Static is a keyword with many meanings, and in this particular case, it means not global (paraphrasing) It means that each .cpp file has its own copy of the variable. Thus, when you initialize in main.cpp, it is initialized ONLY in main.cpp. The other files have it still uninitialized. First thing to fix this would … Read more