Closed Thread Icon

Topic awaiting preservation: Can you set a variable so it can be used through all functions? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12733" title="Pages that link to Topic awaiting preservation: Can you set a variable so it can be used through all functions? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Can you set a variable so it can be used through all functions? <span class="small">(Page 1 of 1)</span>\

 
H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 05-13-2003 02:59

Just a quick question.. Is there a way to do it, rather then declaring a global variable in the functions you need, set them so they can be used through all functions?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-13-2003 04:00

you can define your own constants (however once defined they can not be changed like a normal variable, they can just be redefined). I use this method for things like DB_NAME etc with MySQL and other site constants.

You should also be able to assign new variables to the $GLOBALS superglobal array but I haven't tried this.

The third thing to look into is passing by refrence.

You may want to look at why you need to do this before finding a solution. There's a lot of good reasons you want to keep variables within their scope.



.:[ Never resist a perfect moment ]:.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 05-13-2003 04:04

Thanks for that, yeh your right, its probalby unneccesary =/

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-13-2003 08:39

yeah, needing a global in every function, that is not a constant, is definatly a code smell!

« BackwardsOnwards »

Show Forum Drop Down Menu