Aaron Yodaiken
Aaron Yodaiken

Reputation: 19551

why do variables in namespaces break into the global scope, and what should I do to address this?

I'd like to have arrays in my namespace which all functions in the namespace can access.

Is there no way to do this without resorting to names like $_MYNAMESPACE1_NAMESPACE2_NAMESPACE3_array1? I suppose I could make a class in the namespace which contains static arrays, but that seems pretty inefficient.

Upvotes: 0

Views: 203

Answers (1)

deceze
deceze

Reputation: 522024

Indeed, you cannot namespace variables. You can only namespace classes, interfaces, functions and constants. Since variables outside functions can only be accessed using the global keyword, and global is usually an anti-pattern, this is probably not the solution you're looking for anyway. A class seems like the way to go.

Upvotes: 2

Related Questions