Hi. I have a long function with many if statements and such. The first thing i do in my function is this: $text = file($read_text_file);
The $text array contain all text in the site therefor I need this array to be available in my entire function and I though I would accomplice this by defining the variable first thing in the function, ...
Hi All,
I'm writing an NSString category that requires an NSNumberFormatter. I'm stuck between initing and releasing one every time my category is used to print a string in a certain way or initing the formatter in my app and passing it through. The NSNumberFormatter has a couple of config calls run on it first to make it work just ri...
An Example
Suppose we have a text to write and could be converted to "uppercase or lowercase", and can be printed "at left, center or right".
Specific case implementation (too many functions)
writeInUpperCaseAndCentered(char *str){//..}
writeInLowerCaseAndCentered(char *str){//..}
writeInUpperCaseAndLeft(char *str){//..}
and so on...
...
Hi. I have this code `
require("db_connect.php");
function xx()
{
$conn = db_connect(); //here it works
(...)
date_default_timezone_set('Europe/Paris');
if(time() <= $x[0]){
(...)
}else
{
(...)
for...
So I got a lot of responses from this site that global variables are bad and kill puppies.
What if I use such variables like this:
function get_stuff(){
global $stuff;
if(!stuff) $stuff = 'candy';
return $stuff;
}
function screen_output(){
$stuff = get_stuff;
echo $stuff;
}
does this make the code better than using 'global...
Global state is conventionally frowned upon. However, I think I can use it clientside to make my app simpler.
I have an AJAX web app that sets up several values when the user logs in - user id, as well as some other information. This info does not change for the lifetime of the app.
I also have a cache of data to minimize trips to the...
Hello,
I am beginner in PHP and i read in manual that $_REQUEST is a associative array consisting of cookies, get and post arrays. I want to know which takes precedence in request array.
Say, suppose i have a variable user in $_POST as well as $_COOKIE, and if i use echo $_REQUEST['user'] then which would print. I tried it and i get th...
Is there any reason why I shouldn't do something like the following (to avoid using a hidden field to store the temporary information)? I'm using jQuery syntax for brevity but it's a general JavaScript question.
function editComments() {
window.currentComments = $('#commentsTextBox').val();
$('#commentsTextBox').removeAttr("read...
I have a MS C++ project (let's call it project A) that I am currently compiling as a static library (.lib). It defines a global variable foo. I have two other projects which compile separately (call them B and C, respectively) and each links the shared static library A in. Both B and C are dll's that end up loaded in the same process. I ...
Yes I know global variables is a bad practice, but ease up on that rule for this one :P
My code:
include('something.php'); //where $from is declared
function myfunc() {
global $from;
echo "from(myfunc)=$from<br />";
...
}
echo "from=$from<br />";
myfunc();
The result is:
from=2010-05-01
from(myfunc)=
What's going on?...
Hi. I have an array for all the cars in a online game I'm making that look like this:
$GLOBALS['car_park'] = array (
"Toyota iQ3", "Think City", "Lancia Ypsilon", "Smart fourtwo", "Chevrolet Matiz", "Mazda 2", "Peugeot 107", "Nissan Micra", "Mercedes-Benz 310" /* dårlige biler */
, "Lexus IS-F", "BMW M3 CSL",...
Hello,
I have created a Variable called "myDBManager" in my AppDelegate:
@interface myAppDelegate : NSObject <UIApplicationDelegate> {
MyDBManager *myDBManager;
}
@property (nonatomic, retain) MyDBManager *myDBManager;
@end
which I use in most other classes as a global Variable holding all my critical application data. It gets o...
I'm using C (not C++) and I'm unsure how to avoid using global variables.
I have a pretty decent grasp on C, its syntax, and how to write a basic application, but I'm not sure of the proper way to structure the program.
How do really big applications avoid the use of global variables? I'm pretty sure there will always need to be at lea...
Hi,
I'm using MVC2 and VS2010 developing a website and need to use Application State global values. I can set a value like 'Application["hits"]=0;' in Global.asax but when trying to use the same in an MVC controller always get the following error:
The name 'Application' does not exist in the current context
I have also tried using in...
When we should use global variable and when class variable and why?
I hope your experiences and ideas to share with us who are novice in this platform.
Example:
Let, i need to trace timestamp and position of touch events (eg. touch start, end) on a layer. I can trace it using global variable or class variable of the class which imple...
What exactly is global data?
This may seem like a very rudimentary question but the reason I'm asking is because I'm wondering has the term become stretched over time - i.e it dosn't just apply to data in the "Global" namespace (in c++) or a variable that is available in every scope.
So, what do you consider to be global data?
...
I'm afraid this is a bit of an abstract question. I'm basically writing an iPhone game which revolves around a Pet, a bit like a tamagotchi for example. I've created a Pet object, which contains all the data relevant to the Pet's status. The rest of the program accesses the Pet's data and performs relevant actions.
The pet is saved to ...
Hello,
Consider a javascript file script.js which contains the code alert(theVar);
Now, i linked the js file to the document like
<script type="text/javascript">
var theVar= 'a alert';
</script>
<script type="text/javascript" src="script.js"></script> //Contains alert(theVar);
The variable theVar is used and i get a alert. This ...
Hi Guys,
This is a follow up question from http://stackoverflow.com/questions/3238690/problem-with-array-assignment
I now have addcube done like so.. and all works as expected, when I print the array. but when I print the same index's AFTER assignment in another class It tells me their equal to 0. So the values are not 'saving'. Why is...
Hi,
What is default storage class of a global variable?
While searching on web I found, some sites say it is static. But, static means internal linkage and the variable can not be available outside the file scope i.e it should not be available to other object files. But, they still can be accessed to other files using declarations like...