Variables in namespaces are global!

2009 April 11
tags:
by monzee

This surprised me:

namespace foo
{
    $foo = 'foo';
}

namespace bar
{
    echo $foo; // foo
}

I was looking for a way to import a namespace variable inside a function in the same namespace and the only way I found was to use global $foo; inside the function, which I thought was defeating the whole purpose of namespaces. Then I found out that there’s no such thing as namespace variables! That makes me feel less guilty about using global, but that’s still retarded.

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS