views:

225

answers:

3

Is there a way to make all variables global?

+4  A: 

It doesn't matter what you're trying to do, but this is a bad way of going about it. You'll be much better off just passing variables as arguments to functions or by declaring them global there.

but in short, there is no simple way to do it without a lot of global statements.

GSto
A: 

ok :) I was using a controller file to pass views and classes from the requested URI but for the view to read a variable from the class loaded before hand, it needs to be global, so i'll just make them global manually.

tarnfeld
*for the view to read a variable from the class loaded before hand, it needs to be global* : false. Edit your question to include this. Also, this should be a comment not another answer.
Roatin Marth
In the case you're describing, could you use $_SESSION to store the classes, or the data you're getting from the classes? That may also be a good solution (hard to tell without more information).
GSto
+3  A: 

Quick and dirty way:

$GLOBALS += get_defined_vars();

I don't know if this hack is portable (it works on PHP 5.3.1) and I suspect the objects are cloned.

ntd