1

Is there a way to declare a variable so it is available in all functions. Basically I want to call: Global $varName; automatically for every function. And no, I can't use a constant.

I don't think its possible but wanted to ask anyway. Thanks! :D

1
  • In all functions? Of A class? Or the entire app? Commented Nov 23, 2009 at 8:31

3 Answers 3

3

That's pretty oldschool and not recommended. If you want to use variables whereever you want consider using sessions of passing through variables if you're on an object oriented tour ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Alright, thats more or less what I thought. Thanks for the advice.
1

There is a $GLOBALS variable and a globals keyword.Check out example 1 and 2 on this page in the documentation.

But using a global variable is usually a sign of bad structure in your code.

1 Comment

Yah, I was looking at that page earlier. I'll try to come up with a different way to do it. Thanks.
0

I don't think variables can be globally visible the way you want bnut functions are.

You can declare two functions to access you data : on for reading, one for writing.

But anyway beware : if you change it from many places you will have hard times understanding what's going on when faced with a bug !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.