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
2009-12-15 19:11:50
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
2009-12-15 19:13:44
*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
2009-12-15 19:19:23
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
2009-12-15 19:20:01
+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
2009-12-15 19:54:31