![]() |
PHP Namespace Issue - What do you guys think?
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.
That is the problem as I see it. How does PHP know where it's going when you make the following declaration: php Code:
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? |
Hmm tis an interesting problem, the only ways I can think of is to:
A: not allow functions inside a namespace but not in a class. B: change the character to access namespaces. C: Not allow you to name classes with the same names as namespaces. From the sounds of it with current PHP 5.3.0 implementation of namespaces the only way to successfully call the static is to instantiate the class and call the static like: PHP Code:
or perhaps use reflection? PHP Code:
|
This is the solution they came up with: php.internals: </endnamespacediscussion>
Namespace separator is now a backslash, so TalkPHP\r\n is now a valid namespace. What do we all think? |
php just keeps getting nastier and nastier to work with. They really need to clean it up. They need to make an entire version where they just clean up everything. Have you ever noticed that if you inherit a php application from another developer it is always so much harder to follow then a coldfusion, or asp.net app. Whats the deal with that. This case as you mentioned wildhoney is just another example of this mess being created.
|
I don't think PHP is necessarily getting harder to work with because of poor design but because some of the more advanced concept such as Namespaces can't be dealt with the KISS manner PHP is so famous for. If it stuck to that I think it would turn into PHP's Achilles's Heel.
|
Argh noooo, sigh.
Sure it solves the problems with namespaces but it looks ugly and will confuse people. not to mention making IDE's and editors go insane trying to parse the namespaces as escape sequences. What was wrong with just poping an error when a name collision occurs? |
This makes in interesting read, its a transcript of an IRC discussion with some PHP's developers
http://wiki.php.net/_media/rfc/php.n...or&cache=cache There is quite alot but its pretty interesting. I still think this ambiguity issue need not exist, if people just thought about how they write their apps! But it seems the PHP devs want to mollycoddle the lesser mortals that are PHP users, therefore resulting in this rather hackish looking 'patch', thats just my opinion. _____________ |
Doh! double post, *sigh* fail
|
| All times are GMT. The time now is 04:28 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0