Now, I don't know a whole lot about this topic, as I've not been keeping up with the Jones', as it were. I'm quite rusty in terms of PHP news, and so perhaps other people could explain it better for me. It would be appreciated!
As far as I can see, the problem with the namespaces is when there is a function inside a namespace, outside of a class, then there arises a naming problem. It was explained well to me by a friend of mine called Kalle.
- namespace TalkPHP::Test; function Talk() {}
- namespace TalkPHP; class Test { public function Talk() {} }
That is the problem as I see it. How does PHP know where it's going when you make the following declaration:
php Code:
use Namespace TalkPHP;
Test::Talk();
PHP would surely get confused there, and that's the problem. It wouldn't know which to call because they've allowed functions to be placed outside of classes, but inside namespaces. I don't believe other languages, such as ASP, or perhaps Java, allow that. Any items inside a namespace have to be in a class. Although I've not worked with either of those languages, so I don't know if that's true.
I personally believe that no functions should be allowed to be placed inside namespaces, without an accompanying class. It seems silly to me. Surely you'll be using namespaces in an OOP environment, and in OOP programming, I don't remember the last time I required a custom function outside of a class. Then again though, I have used static functions inside of classes to mimic namespaces, in absence of namespaces in earlier versions of PHP.
Many have suggested different characters instead of the double colon (
::) to access a namespace. What do other people think to this problem, and what's the best way to overcome it, in your humble opinion?