![]() |
Namespaes?
I just got the newsletter... what exactly are namespaces?
|
I'm sure others can give you a better description, but in a nutshell, namespaces are essentially a way in which to cipher of various code into namespaces. Think of a namespace as a category. Therefore anything in that category can have the same function name as another function in a different namespace (or category).
Basically, when you and others develop a PHP script now, you'll see you have to append some text that identifies your script to each class you create for that script, but with namespaces you can place all your classes in a namespace and all the classes within there can be named whatever you like, because they won't conflict with anything else. Welcome back to TalkPHP by the way :-) It's a pleasure to have you round again! |
I still don't get what namespaces are. Any real world examples?
|
|
Thanks for the welcome O.o.
I didn't think I was gone that long! (I was caught up in school work, and trying to find a good book on MySQL). So a namespace is something used in OOP? |
Correct me if I am wrong, but from my very limited understanding, it appears to give classes their own level of scope. PHP classes were totally global before. This meant that if you named your class something like getUserName, no one else could in a large project. Namespaces will allow duplicate class names to happen in instances where more than one library in a project might have similar functionality. Before, one would have to append some sort of unique prefix to the class name in order to insure its uniqueness. This could have resulted in very long class names.
|
namespaces can be used to help you organize your classes. More importantly, namespaces help programmers aviod name clashes and stupidly long class names (if we were to prefix class names to stop clashing) like this:
Zend_Search_Lucene_Analysis_Analyzer_Common_Text_C aseInsensitive from what i have been reading, php's namespaces will look like this: PHP Code:
|
| All times are GMT. The time now is 11:20 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0